描述
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. 直接下载:Windows 10正式版官方原版镜像!

    本文搜集整理微软官方发布的Windows 10正式版镜像下载链接,从RTM原始正式版开始,按照时间倒序排列,即越往上的越新. 注意:以下资源均来自于微软官方原版,ed2k可视为P2P下载链接.下载完成 ...

  2. HTML页面禁用Enter键自动提交表单

    今天在开发页面时,遇到一个小BUG,,如下图 在页面的文本框获取焦点之后,再按键盘上的Enter键,页面form就会自动提交.如下是页面禁止Enter自动提交代码: document.onkeydow ...

  3. Linux命令:chown

    Linux命令:chmod https://baijiahao.baidu.com/s?id=1616750933810368135&wfr=spider&for=pc chmod - ...

  4. Python读取图片尺寸、图片格式

    Python读取图片尺寸.图片格式 需要用到PIL模块,使用pip安装Pillow.Pillow是从PIL fork过来的Python 图片库. from PIL import Image im = ...

  5. JQUERY 简单易用的提示框插件

    业务开发过程中,为了避免用户的误操作,提示框是必要的,于是琢磨出了下面这个使用,方便的提示框 还要引入遮罩层的样式如下: /*弹出层*/.input{height: 32px;border: 1px ...

  6. FMS Dev Guide学习笔记(权限控制)

    一.开发交互式的媒体应用程序 1.关于访问(权限)控制     当一个用户访问服务器的时候,默认情况下,他可以访问所有的流媒体文件和共享对象.但是你可以使用服务端ActionScript为流媒体文件和 ...

  7. border&background1

    1.border-radius border-top-left-radius:10px; = border-top-left-radius:10px 10px; (水平10px 竖直10px 被正圆切 ...

  8. java语言 找出文章中出现次数最多的单词

    package english; import java.io.File; import java.util.Scanner; import java.io.FileNotFoundException ...

  9. netty 集成 wss 安全链接

    netty集成ssl完整参考指南(含完整源码) 虽然我们在内部rpc通信中使用的是基于认证和报文头加密的方式实现安全性,但是有些时候仍然需要使用SSL加密,可能是因为对接的三方系统需要,也可能是由于o ...

  10. Python Try Except

    Python Try: Except Except 类型一: try: file_size = os.path.getsize('maoyan.csv'); except OSError as err ...