题意:

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. schtasks命令遇见ERROR: The request is not supported.

    执行schtasks命令的环境,下文为机器1:windows server 2008 r2 工作任务(Schedules)所在的机器环境,下文为机器2:windows server 2003 当在机器 ...

  2. .Net IE10 _doPostBack 未定义

    问题描述:用.Net写的LinkButton触发后台是js报错:_doPostBack 未定义 网上资料显示这种情况是当前framework不能识别IE10版本,把该浏览器做降级处理导致JS错误,解决 ...

  3. BZOJ 3160 万径人踪灭 解题报告

    这个题感觉很神呀.将 FFT 和 Manacher 有机结合在了一起. 首先我们不管那个 “不能连续” 的条件,那么我们就可以求出有多少对字母关于某一条直线对称,然后记 $T_i$ 为关于直线 $i$ ...

  4. WCF 在VS中,添加服务引用,地址输入http://ip/Service.svc,点击前往,提示错误,内容如下:

    WCF的service端的webconfig如下: <?xml version="1.0"?> <configuration> <system.ser ...

  5. CloudTest 事务监控:千呼万唤始出来

    SmartBear 数据表明,如果 Amazon 的加载时间延长 1 秒,那么一年就会减少 16 亿美元的营收.用户与网站互动的过程中,如果加载时间超过3秒,57% 的用户会流失.可见,网站的加载时间 ...

  6. Socat

    http://www.oschina.net/p/socat/ tcpick https://sourceforge.net/projects/tcpick/

  7. RCC 2014 Warmup (Div. 2) ABC

    题目链接 A. Elimination time limit per test:1 secondmemory limit per test:256 megabytesinput:standard in ...

  8. thinkphp 定制错误页面

    在前台配置文件里加上: 'TMPL_EXCEPTION_FILE' => '.Public/tpl/error.html',// 异常cuowu页面的模板文件 然后在Public下新建一个tpl ...

  9. HeadFirst设计模式之门面模式

    一. 1.The Facade Pattern provides a unifi ed interface to a set of interfaces in a subsytem. Facade d ...

  10. git rebase无法处理的问题

    在进行代码整理的时候,遇到了冲突 现在chucklu_master分支指向这个commit SHA-1: 88fa1ee9263402626d85b5a4362e1b620935953f * remo ...