hdu4614Vases and Flowers(线段树,段设置,更新时范围的右边值为变量)
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 one blank line after each test case.
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
2
1 9
4
Can not put any one.
2 6
2
0 9
4
4 5
2 3
#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(线段树,段设置,更新时范围的右边值为变量)的更多相关文章
- HDU I Hate It(线段树单节点更新,求区间最值)
http://acm.hdu.edu.cn/showproblem.php?pid=1754 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分 ...
- hdu4267线段树段更新,点查找,55棵线段树.
题意: 给你N个数,q组操作,操作有两种,查询和改变,查询就是查询当前的这个数上有多少,更改是给你a b k c,每次从a到b,每隔k的数更改一次,之间的数不更改,就相当于跳着更新. 思路: ...
- UVA11992不错的线段树段更新
题意: 给你一个矩阵,最大20*50000的,然后有三个操作 1 x1 y1 x2 y2 v 把子矩阵的值全部都加上v 2 x1 y1 x2 y2 v 把子矩阵的值全部都变成v 2 x ...
- hdu4614 Vases and Flowers 线段树+二分
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 题意: 给你N个花瓶,编号是0 到 N - 1 ,初始状态花瓶是空的,每个花瓶最多插一朵花. ...
- poj3468A Simple Problem with Integers(线段树的区域更新)
http://poj.org/problem?id=3468 真心觉得这题坑死我了,一直错,怎么改也没戏,最后tjj把q[rt].lz改成了long long 就对了,真心坑啊. 线段树的区域更新. ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1698:Just a Hook(线段树,区间更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 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 ...
- hdu1698线段树的区间更新区间查询
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
随机推荐
- return File
public ActionResult DownloadMessage() { string strExportData = "无数据!"; byte[] data = Syste ...
- Tomcat 7.0配置SSL的问题及解决办法
http://dong-shuai22-126-com.iteye.com/blog/1830209 以前一直在用Tomcat 6.0.29版本,今下载了apache-tomcat-7.0.33- ...
- 搜集的一些RTMP项目,有Server端也有Client端
查询一些RTMP的协议封装时找到了一些RTMP开源项目,在这里列举一下,以后有时间或是有兴趣可以参考一下: just very few of them. Red5 only contains a se ...
- <七>面向对象分析之UML核心元素之包
一:基本概念
- android直接读取数据库文件
public class Dictionary extends Activity implements OnClickListener, TextWatcher{ private final ...
- linux下网络排错与查看
基本的故障排除错误 故障的排除一定是先简单后复杂的,有的人把上述的文件反复配置,就是上不了网,一直都认为是系统出了故障,想重装机子.结果发现原来是网线压根就没插上. 排错要慢慢的按部就班的来: (1) ...
- 完美完全卸载Oracle 11g数据库
Oracle 11g可在开始菜单中卸载,然后同时需要删除注册表中相关内容. 操作系统:windows10专业版. 卸载步骤: 1.停用oracle服务:进入计算机管理,在服务中,找到oracle开头的 ...
- 怎样在 Ubuntu 中修改默认程序
导读 作为一个新手,你需要知道如何在 Ubuntu 中修改任何默认程序,这也是我今天在这篇指南中所要讲的. 对于我来说,安装 VLC 多媒体播放器是安装完 Ubuntu 16.04 该做的事中最先做的 ...
- 七中滤波方法测试matlab实现
http://blog.163.com/xiaheng0804@126/blog/static/1205282120132129471816/ 创建两个混合信号,便于更好测试滤波器效果.同时用七中滤波 ...
- aspx与ascx,ashx的用法详细的总结介绍
这篇文章主要是对aspx与ascx,ashx的用法进行了详细的总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助 做asp.net开发的对.aspx,.ascx和.ashx都不会陌生.关于它们,网 ...