L - Vases and Flowers - hdu 4614(区间操作)
#include<algorithm>
#include<stdio.h>
using namespace std; #define lson r<<1
#define rson r<<1|1 const int MAXN = 1e5+; struct stgmentTree
{//sum花瓶的剩余量
int x, y, sum, cover;//cover, 操作1赋值为释放花瓶,操作2沾满花瓶
int mid(){return (x+y)>>;}
int len(){return y-x+;}
}a[MAXN<<];
int ans;
void Build(int r, int x, int y)
{
a[r].x = x, a[r].y = y;
a[r].sum = a[r].len(), a[r].cover = ; if(x == y)
return ; Build(lson, x, a[r].mid());
Build(rson, a[r].mid()+, y);
}
void Down(int r)
{
if(a[r].x != a[r].y && a[r].cover)
{
a[lson].cover = a[rson].cover = a[r].cover;
a[lson].sum = a[r].cover== ? : a[lson].len();
a[rson].sum = a[r].cover== ? : a[rson].len(); a[r].cover = ;
}
}
void Insert(int r, int x, int y, int op)
{
if(a[r].x == x && a[r].y == y)
{
ans += a[r].len()-a[r].sum;
a[r].cover = op;
a[r].sum = (op== ? : a[r].len()); return ;
} Down(r); if(y <= a[r].mid())
Insert(lson, x, y, op);
else if(x > a[r].mid())
Insert(rson, x, y, op);
else
{
Insert(lson, x, a[r].mid(), op);
Insert(rson, a[r].mid()+, y, op);
} a[r].sum = a[rson].sum + a[lson].sum;
}
int QueryPreSum(int r, int k)//求k前面的空花瓶数
{
Down(r); if(a[r].x == a[r].y)
return ;
if(k <= a[r].mid())
return QueryPreSum(lson, k);
else
return a[lson].sum + QueryPreSum(rson, k);
}
int QueryLast(int r, int p)//查找第p个花瓶位置
{
Down(r); if(a[r].x == a[r].y)
return a[r].x; if(a[lson].sum >= p)
return QueryLast(lson, p);
else
return QueryLast(rson, p-a[lson].sum);
} int main()
{
int T; scanf("%d", &T); while(T--)
{
int N, M, op, x, y, L, R; scanf("%d%d", &N, &M); Build(, , N-); while(M--)
{
scanf("%d%d%d", &op, &x, &y);
if(op == )
{
int PreSum = QueryPreSum(, x); if(PreSum == a[].sum)
printf("Can not put any one.\n");
else
{
L = QueryLast(, PreSum+); if(PreSum+y >= a[].sum)
PreSum = a[].sum;
else
PreSum += y;
R = QueryLast(, PreSum); Insert(, L, R, ); printf("%d %d\n", L, R);
}
}
else
{
ans = ;
Insert(, x, y, );
printf("%d\n", ans);
}
} printf("\n");
} return ;
}
/*
2
10 8
1 2 5
2 3 4
1 0 8
2 2 5
1 6 1
1 4 4
1 2 3
*/
L - Vases and Flowers - hdu 4614(区间操作)的更多相关文章
- L - Vases and Flowers HDU - 4614 线段树+二分
题意 给出一排空花瓶 有两种操作 1是 从A花瓶开始放F朵花 如果当前瓶有花就跳过前往下一个 直到花用完或者 瓶子到了最后一个为止 输出 成功放花的第一个和最后一个 如果没有输出 can not. ...
- HDU-4614 Vases and Flowers 线段树区间更新
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 线段树保存区间是否被覆盖以及区间的和即可,在询问的时候在线段树上二分查找就可以了...代码写得比 ...
- 【HDU 4614】Vases and Flowers(线段树区间更新懒惰标记)
题目0到n-1的花瓶,操作1在下标a开始插b朵花,输出始末下标.操作2清空[a,b]的花瓶,求清除的花的数量.线段树懒惰标记来更新区间.操作1,先查询0到a-1有num个空瓶子,然后用线段树的性质,或 ...
- 2013 多校联合2 D Vases and Flowers (hdu 4614)
Vases and Flowers Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others ...
- HDU 4614 Vases and Flowers(线段树+二分)
Vases and Flowers Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others ...
- HDU 4614 Vases and Flowers (2013多校2 1004 线段树)
Vases and Flowers Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others ...
- HDU-4614 Vases and Flowers(线段树区间更新+二分查找)
http://acm.hdu.edu.cn/showproblem.php?pid=4614 Time Limit: 4000/2000 MS (Java/Others) Memory Limi ...
- HDU 4578——Transformation——————【线段树区间操作、确定操作顺序】
Transformation Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others)T ...
- HDU 1754 I Hate It (Splay 区间操作)
题目大意 维护一个序列,支持两种操作 操作一:将第x个元素的值修改为y 操作二:询问区间[x,y]内的元素的最大值 解题分析 splay的区间操作,事先加入两个编号最小和最大的点防止操作越界. 具体的 ...
随机推荐
- linux sysvinit与upstart [转]
linux sysvinit与upstart(1) linux sysvinit与upstart(2) linux sysvinit与upstart(3)
- python练习程序_员工信息表_基本实例
python实现增删改查操作员工信息文件,可进行模糊查询: http://edu.51cto.com/lesson/id-13276.html http://edu.51cto.com/lesson/ ...
- 9.2noip模拟试题
题目名称 改造二叉树 数字对 交换 英文名称 binary pair swap 输入文件名 binary.in pair.in swap.in 输出文件名 binary.out pair.out ...
- codevs3008加工生产调度(Johnson算法)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...
- System.Web.HttpContext.Current.Session获取值出错
在自定义类库CS文件里使用System.Web.HttpContext.Current.Session获取Session时提示错误:未将对象引用设置到对象的实例. 一般情况下通过这种方式获取Sessi ...
- 【NEERC 2003】有向图破坏
[题目描述] Alice和Bob正在玩如下的游戏.首先Alice画一个有N个顶点,M条边的有向图.然后Bob试着摧毁它.在一次操作中他可以找到图中的一个点,并且删除它所有的入边或所有的出边. Alic ...
- nginx配置无效的问题
今天修改nginx的一个配置文件,却怎么都没效果,发现是启动nginx指定的配置文件不一样. #ps aux|grep nginx root 17672 0.0 0.0 45856 2 ...
- MyBatis学习笔记(2)——缓存
一级缓存:基于PerpetualCache的HashMap本地缓存,其存储作用域为Session,当Session flush或 close之后,该Session 中的所有Cache将被清空 二级缓存 ...
- (转载)最实用的清除浮动代码 css的文字过长裁剪后面跟着省略号
css: .clearfloat:after{display:block;clear:both;content:"";visibility:hidden;} .clearfloat ...
- CSS 字体描边
-webkit-text-stroke: 2px #; text-stroke: 2px #; -o-text-stroke: 2px #;