题意:

n个花瓶(0-n-1) 现有两个操作,

操作1 给a,f 从a位置开始向后连续插f个花(一个花瓶插一个)若当前花瓶有花则向后找,直到n-1位置如果还有多余的花则丢掉求查完花的第一和最后一个位置。

操作2 L,R 清空[l,r]花瓶内的花,并输出花的数量。

分析:

本题关键是用二分求插花的首末的位置,其他是基本的区间更新。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<1|1
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
#define N 50010
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int vempty[N*],setv[N*],n,q,p,pos;
void pushup(int rt){
vempty[rt]=vempty[rt<<]+vempty[rt<<|];
}
void pushdown(int rt,int len){
if(setv[rt]!=-){
setv[rt<<]=setv[rt<<|]=setv[rt];
vempty[rt<<]=(len-len/)*setv[rt];
vempty[rt<<|]=len/*setv[rt];
setv[rt]=-;
}
}
void build(int l,int r,int rt){
setv[rt]=-;
vempty[rt]=r-l+;
if(l==r)return ;
int m=(l+r)>>;
build(lson);
build(rson);
}
void update_add(int L,int R,int l,int r,int rt){
if(L<=l&&R>=r){
vempty[rt]=setv[rt]=;
return;
}
pushdown(rt,r-l+);
int m=(l+r)>>;
if(L<=m)update_add(L,R,lson);
if(R>m)update_add(L,R,rson);
pushup(rt);
}
void update_cle(int L,int R,int l,int r,int rt){
if(L<=l&&R>=r){
setv[rt]=;
vempty[rt]=(r-l+);
return;
}
pushdown(rt,r-l+);
int m=(l+r)>>;
if(L<=m)update_cle(L,R,lson);
if(R>m)update_cle(L,R,rson);
pushup(rt);
}
int query(int L,int R,int l,int r,int rt){
if(L<=l&&R>=r){
return vempty[rt];
}
pushdown(rt,r-l+);
int num=;
int m=(l+r)>>;
if(L<=m)num+=query(L,R,lson);
if(R>m)num+=query(L,R,rson);
pushup(rt);
return num;
}
int main()
{
int t,k,a,b;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&q);
build(,n,);
while(q--){
scanf("%d%d%d",&k,&a,&b);
if(k==){
int ans=query(a+,n,,n,);
if(ans==){
printf("Can not put any one.\n");
continue;
}
//二分首位置
int num=,l=a+,r=n,ll,rr;
while(l<=r){
int m=(l+r)>>;
int tmp=query(a+,m,,n,);
if(tmp<num)l=m+;
else
r=m-;
}
ll=l;
//二分末位置
num=ans<b?ans:b,l=a+,r=n;
while(l<=r){
int m=(l+r)>>;
int tmp=query(a+,m,,n,);
if(tmp<num)l=m+;
else
r=m-;
}
rr=l;
printf("%d %d\n",ll-,rr-);
update_add(ll,rr,,n,);
}
else{
int tmp=b-a+-query(a+,b+,,n,);
printf("%d\n",tmp);
update_cle(a+,b+,,n,);
}
}
printf("\n");
}
return ;
}

HDU 4614-Vases and Flowers(线段树区间更新)的更多相关文章

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

    题目链接 比赛的时候一直想用树状数组,但是树状数组区间更新之后,功能有局限性.线段树中的lz标记很强大,这个题的题意也挺纠结的. k = 1时,从a开始,插b个花,输出第一个插的位置,最后一个的位置, ...

  2. HDU-4614 Vases and Flowers 线段树区间更新

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 线段树保存区间是否被覆盖以及区间的和即可,在询问的时候在线段树上二分查找就可以了...代码写得比 ...

  3. hdu 4614 Vases and Flowers 线段树

    题目链接 一共n个盒子, 两种操作, 第一种是给出两个数x, y, 从第x个盒子开始放y朵花, 一个盒子只能放一朵, 如果某个盒子已经有了, 那么就跳过这个盒子放下面的盒子. 直到花放完了或者到了最后 ...

  4. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  5. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  6. (简单) HDU 1698 Just a Hook , 线段树+区间更新。

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

  7. HDU 1698 Just a Hook(线段树区间更新查询)

    描述 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes ...

  8. hdu - 1689 Just a Hook (线段树区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...

  9. 2014多校第四场1006 || HDU 4902 Nice boat (线段树 区间更新)

    题目链接 题意 : 给你n个初值,然后进行两种操作,第一种操作是将(L,R)这一区间上所有的数变成x,第二种操作是将(L,R)这一区间上所有大于x的数a[i]变成gcd(x,a[i]).输出最后n个数 ...

  10. HDU 1698 Just a Hook 线段树区间更新、

    来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...

随机推荐

  1. hdu 4710 Balls Rearrangement()

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 [code]: #include <iostream> #include <cstdio ...

  2. uva 437 hdu 1069

    dp  将石块按三个面存入队列  按底面积排序  dp就最大高度  按嵌套矩形最长路做做法 #include <iostream> #include <cstdio> #inc ...

  3. spoj 362

    规律还是比较好找的  大数除法 #include <cstdio> #include <cstring> int len,a[1000],q; int cc[] = {0,1, ...

  4. java核心技术记录

    Java是一种强类型的语言,这意味着必须为每一个变量声明一种类型.在java中,一共有8种基本类型,其中4种整型.2种浮点型.1种用于表示Unicode编码的字符单元的字符类型char和一种用于表示真 ...

  5. 云风的BLOG❳可靠 UDP 传输

    http://mp.weixin.qq.com/s?__biz=MzA3NjYxOTA0MQ==&mid=405432715&idx=1&sn=2e40ceafd4b298e1 ...

  6. 【HTTP】Fiddler(一) - Fiddler简介和使用

    1.为什么是Fiddler? 抓包工具有很多,小到最常用的web调试工具firebug,达到通用的强大的抓包工具wireshark.为什么使用fiddler?原因如下: a.Firebug虽然可以抓包 ...

  7. hdu 4294 Multiple

    思路: 首先给出一个结论,就是最多用两个数就可以表示任何数的倍数. 证明 :对于一个数字a,可以构造出的数字有 a,aa,aaa,aaaa,aaaaa,…… 每一个数对于n都有一个余数,余数最多有n个 ...

  8. Mac与Linux的一个巨大不同

    就是Mac仍处在桌面市场的商业圈里,尽管它的市场很小,但是正版率却很高,而且还有专门的Mac Store提供付费下载. Linux在桌面市场几乎没有份额,也不会有人会去买它的应用软件,基本上只存在于服 ...

  9. UML各种图画法总结

    <UML 2.4.1 教程> http://www.sparxsystems.cn/resources/uml2_tutorial/ <UML总结(对九种图的认识和如何使用Ratio ...

  10. 在Ubuntu 12.04安装和设置Samba实现网上邻居共享

    转载:http://www.startos.com/ubuntu/tips/2012031333097.html          有微小改动. Samba 是一款功能强大的共享工具,可以实现与win ...