Problem Description
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,m, n表示花瓶数量0~n-1,开始全为空,接下来有m组,每组有数k,a,b;当k=1时, 从a位置开始插花,b为花数量,当花瓶有花时,跳过当前,直到找到空花瓶再插入,输出插入第一支花的位置和最后一支花的位置,花可以没插完,当一支都没有插入则输出Can not put any one.;当k=2时,清空【a,b】的花瓶,并输出在范围内花的数量。
#include<stdio.h>
#define N 50010
struct node
{
int sum,b;//sum为在范围内的花数,b为判断是否全为空或全为满则为1,否则为0
}tree[4*N];
void biulde(int l,int r,int k)
{
int m=(l+r)/2;
tree[k].sum=0; tree[k].b=1;
if(l==r) return ;
biulde(l,m,k*2); biulde(m+1,r,k*2+1);
}
void set_child(int l,int r,int k)
{
int m=(l+r)/2;
tree[k*2].b=tree[k*2+1].b=1;
if(tree[k].sum==r-l+1){
tree[k*2].sum=m-l+1; tree[k*2+1].sum=r-m;
}
else{
tree[k*2].sum=0; tree[k*2+1].sum=0;
}
}
int QL,QR,L,R,ans,n;
void putInFlower(int l,int r,int k)
{
if(ans<=0) return ;
int m=(l+r)/2;
if(L<=l&&r<=R&&tree[k].b)
{
if(!tree[k].sum) {
int tans=ans;
ans-=(r-l+1); tree[k].sum=r-l+1;
if(QL<0) QL=l-1;
QR=r-1;
}
else{//跳动插花范围的右边值,R刚好是插完花的右边范围的最小值,除非超出花瓶数量,则为n
R+=(r-l+1); if(R>n) R=n;
}
return ;
}
if(tree[k].b)
set_child(l,r,k);
tree[k].b=0;
if(L<=m) putInFlower(l,m,k*2);
if(R>m) putInFlower(m+1,r,k*2+1); tree[k].sum=tree[k*2].sum+tree[k*2+1].sum;
if(tree[k].sum==r-l+1||!tree[k].sum)
tree[k].b=1;
}
void clear(int l,int r,int k)
{
int m=(l+r)/2;
if(L<=l&&r<=R)
{
ans+=tree[k].sum; tree[k].b=1; tree[k].sum=0;
return ;
}
if(tree[k].b)
set_child(l,r,k);
tree[k].b=0;
if(L<=m) clear(l,m,k*2);
if(R>m) clear(m+1,r,k*2+1); tree[k].sum=tree[k*2].sum+tree[k*2+1].sum;
if(tree[k].sum==r-l+1||!tree[k].sum)
tree[k].b=1;
}
int main()
{
int t,m,x;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
biulde(1,n,1);
while(m--)
{
scanf("%d%d",&x,&L); L++;
if(x==1){
scanf("%d",&ans);
R=L+ans-1; QL=QR=-1;
putInFlower(1,n,1);
if(QR>=0)
printf("%d %d\n",QL,QR);
else
printf("Can not put any one.\n");
}
else{
scanf("%d",&R); R++; ans=0;
clear(1,n,1);
printf("%d\n",ans);
}
}
printf("\n");
}
return 0;
}

hdu4614Vases and Flowers(线段树,段设置,更新时范围的右边值为变量)的更多相关文章

  1. HDU I Hate It(线段树单节点更新,求区间最值)

    http://acm.hdu.edu.cn/showproblem.php?pid=1754 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分 ...

  2. hdu4267线段树段更新,点查找,55棵线段树.

    题意:      给你N个数,q组操作,操作有两种,查询和改变,查询就是查询当前的这个数上有多少,更改是给你a b k c,每次从a到b,每隔k的数更改一次,之间的数不更改,就相当于跳着更新. 思路: ...

  3. UVA11992不错的线段树段更新

    题意:       给你一个矩阵,最大20*50000的,然后有三个操作 1 x1 y1 x2 y2 v  把子矩阵的值全部都加上v 2 x1 y1 x2 y2 v  把子矩阵的值全部都变成v 2 x ...

  4. hdu4614 Vases and Flowers 线段树+二分

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

  5. poj3468A Simple Problem with Integers(线段树的区域更新)

    http://poj.org/problem?id=3468 真心觉得这题坑死我了,一直错,怎么改也没戏,最后tjj把q[rt].lz改成了long long 就对了,真心坑啊. 线段树的区域更新. ...

  6. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  7. hdu 1698:Just a Hook(线段树,区间更新)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. UVA 12436-Rip Van Winkle's Code(线段树的区间更新)

    题意: long long data[250001]; void A( int st, int nd ) { for( int i = st; i \le nd; i++ ) data[i] = da ...

  9. hdu1698线段树的区间更新区间查询

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

随机推荐

  1. 爬虫技术(五)-- 模拟简单浏览器(附c#代码)

    由于最近在做毕业设计,需要用到一些简单的浏览器功能,于是学习了一下,顺便写篇博客~~大牛请勿喷,菜鸟练练手~ 实现界面如下:(简单朴素版@_@||) button_go实现如下: private vo ...

  2. 8天学通MongoDB——第七天 运维技术

    这一篇我们以管理员的视角来看mongodb,作为一名管理员,我们经常接触到的主要有4个方面: 1.  安装部署 2.  状态监控 3.  安全认证 4.  备份和恢复, 下面我们就一点一点的讲解. 一 ...

  3. Alpha、Beta、RC、GA版本的区别

    Alpha:是内部测试版,一般不向外部发布,会有很多Bug.一般只有测试人员使用. Beta:也是测试版,这个阶段的版本会一直加入新的功能.在Alpha版之后推出. RC:(Release Candi ...

  4. 转载:Unobtrusive JavaScript in ASP.NET MVC 3 隐式的脚本在MVC3

    Unobtrusive JavaScript 是什么? <!--以下是常规Javascript下写出来的Ajax--> <div id="test"> &l ...

  5. 完全二叉树的高度为什么是对lgN向下取整

    完全二叉树的高度为什么是对lgN向下取整呢? 说明一下这里的高度:只有根节点的树高度是0. 设一棵完全二叉树节点个数为N,高度为h.所以总节点个数N满足以下不等式: 1 + 21 + 22 +……+ ...

  6. NSIS 2.0界面快速入门

    NSIS 2.0 版本支持定制的用户界面.所谓的 Modern UI(下称 MUI) 就是一种模仿最新的 Windows 界面风格的界面系统.MUI 改变了 NSIS 脚本的编写习惯,它使用 NSIS ...

  7. CURL使用

    最近开发的游戏之中需要用到大量的客户端与服务端交互的 东西,开始参考大量的技术文章,感觉是五花八门,眼花缭乱.到后面,真正感受到,学习一门技术,还是需要从它最开始的东西开始学起,要不就是一头雾水,这种 ...

  8. UVA 1663 Purifying Machine (二分图匹配,最大流)

    题意: 给m个长度为n的模板串,模板串由0和1和*三种组成,且每串至多1个*,代表可0可1.模板串至多匹配2个串,即*号改成0和1,如果没有*号则只能匹配自己.问:模板串可以缩减为几个,同样可以匹配原 ...

  9. 使用AngularJS 进行Hybrid App 开发已经有一年多时间了,这里做一个总结

    一.AngularJS 初始化加载流程 1.浏览器载入HTML,然后把它解析成DOM.2.浏览器载入angular.js脚本.3.AngularJS等到DOMContentLoaded事件触发.4.A ...

  10. IO的阻塞、非阻塞、同步、异步