描述
Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N-1. When she receive some flowers, she will try to put them in the vases, one flower in one vase. She randomly choose the vase A and try to put a flower in the vase. If the there is no flower in the vase, she will put a flower in it, otherwise she skip this vase. And then she will try put in the vase A+1, A+2, ..., N-1, until there is no flower left or she has tried the vase N-1. The left flowers will be discarded. Of course, sometimes she will clean the vases. Because there are too many vases, she randomly choose to clean the vases numbered from A to B(A <= B). The flowers in the cleaned vases will be discarded.

Input
The first line contains an integer T, indicating the number of test cases.
For each test case, the first line contains two integers N(1 < N < 50001) and M(1 < M < 50001). N is the number of vases, and M is the operations of Alice. Each of the next M lines contains three integers. The first integer of one line is K(1 or 2). If K is 1, then two integers A and F follow. It means Alice receive F flowers and try to put a flower in the vase A first. If K is 2, then two integers A and B follow. It means the owner would like to clean the vases numbered from A to B(A <= B).

Output
For each operation of which K is 1, output the position of the vase in which Alice put the first flower and last one, separated by a blank. If she can not put any one, then output 'Can not put any one.'. For each operation of which K is 2, output the number of discarded flowers.
Output one blank line after each test case.

Sample Input
2
10 5
1 3 5
2 4 5
1 1 8
2 3 6
1 8 8
10 6
1 2 5
2 3 4
1 0 8
2 2 5
1 4 4
1 2 3

Sample Output
3 7
2
1 9
4
Can not put any one.

2 6
2
0 9
4
4 5
2 3

题意

爱丽丝有N个花瓶,编号0-N-1,有M个操作

当K=1时,表示从A开始直到插完B朵花后停止,输出第一朵花和最后一朵花插的位置,如果一朵都插不进去输出Can not put any one,如果瓶子不够插输出第一朵插和最后插的位子

当K=2时,表示主人要清空[A,B]花瓶里的花,输出清除了多少朵

题解

线段树区间更新延迟标记,区间查询

当K=1时

如果[A,B]中0的个数为0表示已经插满,输出Can not put any one

如果0的个数>=B朵花,表示可以插B朵

如果0的个数<B朵花,表示只能插0的个数朵花

A点开始二分[A+1,N],区间查询[A,mid]插花的数目,找到能插入B朵花的最左端qr,再二分[A,qr]找到第一个插入的最左端ql,然后得到区间[ql,qr],更新即可

当K=2时

把[A,B]的区间更新

代码

 #include<stdio.h>
#include<algorithm>
using namespace std; const int N=5e4+; struct node
{
int l,r,sum,lazy;
}a[N<<];
void PushUp(int rt)
{
a[rt].sum=a[rt<<].sum+a[rt<<|].sum;
}
void PushDown(int rt)
{
if(a[rt].lazy!=-)
{
a[rt<<].lazy=a[rt<<|].lazy=a[rt].lazy;
a[rt<<].sum=a[rt].lazy*(a[rt<<].r-a[rt<<].l+);
a[rt<<|].sum=a[rt].lazy*(a[rt<<|].r-a[rt<<|].l+);
a[rt].lazy=-;
}
}
void Build(int l,int r,int rt)
{
a[rt].l=l;
a[rt].r=r;
a[rt].sum=;
a[rt].lazy=-;
if(l==r)return;
int mid=(l+r)>>;
Build(l,mid,rt<<);
Build(mid+,r,rt<<|);
}
void Update(int L,int R,int C,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
a[rt].lazy=C;
a[rt].sum=C*(r-l+);
return;
}
int mid=(l+r)>>;
PushDown(rt);
if(L<=mid)Update(L,R,C,l,mid,rt<<);
if(R>mid)Update(L,R,C,mid+,r,rt<<|);
PushUp(rt);
}
int Query(int L,int R,int l,int r,int rt)
{ if(L<=l&&r<=R)
return a[rt].sum;
int mid=(l+r)>>,sum=;
PushDown(rt);
if(L<=mid)sum+=Query(L,R,l,mid,rt<<);
if(R>mid)sum+=Query(L,R,mid+,r,rt<<|);
PushUp(rt);
return sum;
}
int main()
{
int t,n,m,x,y,op;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
Build(,n,);
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&op,&x,&y);
x++;
if(op==)
{
int cnt=n-x+-Query(x,n,,n,),ql=x,qr=n;//x--n未插的个数
if(cnt==)//全是花
{
printf("Can not put any one.\n");
continue;
}
else if(cnt>=y)//只能插y朵
{
int l=x,r=n;
while(l<=r)
{
int mid=(l+r)>>;
cnt=mid-x+-Query(x,mid,,n,);
if(cnt>=y)qr=mid,r=mid-;
else l=mid+;
}
}
else//只能插cnt朵
{
int l=x,r=n;
y=cnt;
while(l<=r)
{
int mid=(l+r)>>;
cnt=mid-x+-Query(x,mid,,n,);
if(cnt>=y)qr=mid,r=mid-;
else l=mid+;
}
}
///二分左区间[x,qr]
int l=x,r=qr;
while(l<=r)
{
int mid=(l+r)>>;
cnt=qr-mid+-Query(mid,qr,,n,);
if(cnt>=y)ql=mid,l=mid+;
else r=mid-;
}
Update(ql,qr,,,n,);
printf("%d %d\n",ql-,qr-);
}
if(op==)
{
y++;
printf("%d\n",Query(x,y,,n,));
Update(x,y,,,n,);
}
}
printf("\n");
}
return ;
}

HDU 4614 Vases and Flowers(二分+线段树区间查询修改)的更多相关文章

  1. HDU 4614 Vases and Flowers(线段树+二分)

    Vases and Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others ...

  2. HDU 4614 Vases and Flowers 【线段树】+【二分】

    <题目链接> 题目大意: 有n个花瓶,每个花瓶中只能放一朵花.两种操作,一种是从A开始放F朵花,如果有的花瓶中已经有花则跳过这个花瓶,往下一个花瓶放:第二种是将区间[A,B]之间花瓶中的花 ...

  3. HDU 4614 Vases and Flowers(线段树+记录区间始末点或乱搞)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 题目大意:有n个空花瓶,有两种操作: 操作①:给出两个数字A,B,表示从第A个花瓶开始插花,插B ...

  4. hdu 4614 Vases and Flowers(线段树:成段更新)

    线段树裸题.自己写复杂了,准确说是没想清楚就敲了. 先是建点为已插花之和,其实和未插花是一个道理,可是开始是小绕,后来滚雪球了,跪了. 重新建图,分解询问1为:找出真正插画的开始点和终止点,做成段更新 ...

  5. hdu 4614 Vases and Flowers(线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 题意: 给你N个花瓶,编号是0  到 N - 1 ,初始状态花瓶是空的,每个花瓶最多插一朵花. ...

  6. HDU4614 Vases and Flowers 二分+线段树

    分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小 #include<iostream> #include<cmath> #includ ...

  7. HDU - 4614 Vases and Flowers(二分+区间修改)

    https://cn.vjudge.net/problem/HDU-4614 题意 n个花瓶,m个操作,花瓶里面有的有花,有的是空的.1操作是从a开始往右放b朵花,花瓶有了的不放,跳过,直到a右边都放 ...

  8. POJ_3468 A Simple Problem with Integers 【线段树区间查询+修改】

    一.题目 POJ3468 二.分析 裸的线段树区间查询+修改. 三.AC代码 #include <cstdio> #include <iostream> #include &l ...

  9. 题解报告:hdu 1698 Just a Hook(线段树区间修改+lazy懒标记的运用)

    Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...

随机推荐

  1. centos服务器如何用命令查看哪个程序内存占用情况,硬盘空间占用

    1.free -m只能查看内存总量情况 2.top M ( 注意M是大写) 3.ps aux|head -1; ps aux | sort -k4nr | head -10 ------------- ...

  2. mobile-net v2 学习记录。我是菜鸡!

    声明:只是自己写博客总结下,不保证正确性,我的理解很可能是错的.. 首先,mobile net V1的主要特点是: 1.深度可分离卷积.用depth-wise convolution来分层过滤特征,再 ...

  3. 服务限流-令牌桶java实现

    此文非常不错,抄自: https://www.cnblogs.com/googlemeoften/p/6020718.html 其他实现 https://www.cnblogs.com/LBSer/p ...

  4. Zabbix监控Zookeeper健康状况

    首先最简单的是监听服务端口,在zabbix界面直接添加监控项 item: zookeeper.status key: net.tcp.listen[2181]   ZooKeeper监控要点:   内 ...

  5. Nginx ssl证书部署方法

    查看当前安装的OpenSSL版本所支持的密码列表,可以使用下列命令:openssl ciphers 苹果ATS检测:https://www.qcloud.com/product/ssl 刚开始&quo ...

  6. HTML+CSS基础课程二

    1.border为系统加边框<style type="text/css"> table tr td,th{border:1px solid #000;} </st ...

  7. python批量操作Linux服务器脚本,key登录(执行命令、上传、下载)(二)

       -*-   2 #批量操作linux服务器(执行命令,上传,下载)   3 #!/usr/bin/python   4 import paramiko   5 import datetime   ...

  8. WilliamChart各种图表效果实现大全《IT蓝豹》

    WilliamChart各种图表效果实现大全,有水平线条表格,有柱状表格等.由LineFragment,BarFragment,StackedFragment,SandboxFragment几个fra ...

  9. centos 卸载和安装软件

    rpm -qa 列出所有已安装软件包 rpm -e packagename  删除软件包 rpm -e --nodeps packagename  强制删除软件和依赖包 rpm -q 包名     查 ...

  10. java中garadle工程没有src问题

    https://www.jb51.net/article/142791.htm 前几天遇到一个问题,就是使用ider创建gradle项目后,src目录没有自动生成出来,今天就给大家分享一下怎么解决. ...