题意:

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. mybatis include标签

    使用mybatis 的include标签达到SQL片段达到代码复用的目的 示例: xml文件 <sql id="paysql"> payid,p.oid,p.bdate ...

  2. EasyUI datagrid 分页Json字符串格式

    //EasyUI datagrid 分页Json字符串格式 //{"total":xx,"rows":[{...},{...}]} total:总数 rows: ...

  3. itext 落雨 out of membery Memory Optimization

    Memory Optimization If a document deals with a lot of data or large elements, such as images, it is ...

  4. 如何优化 Android Studio 启动、编译和运行速度?

    作为一名 Android 程序员,选择一个好的 IDE 工具可以使开发变得非常高效,很多程序员喜欢使用 Google 的 Android Studio来进行开发,但使用起来有时会出现卡顿等问题.本文介 ...

  5. socket选项自带的TCP异常断开检测

    TCP异常断开是指在突然断电,直接拔网线等等情况下,如果通信双方没有进行数据发送通信等处理的时候,无法获知连接已经断开的情况. 在通常的情况下,为了使得socket通信不受操作系统的限制,需要自己在应 ...

  6. 阿里云,CentOS下yum安装mysql,jdk,tomcat

    首先说明,服务器是阿里云的,centos6.3_64位安全加固版.首先需要登陆进来,使用的是putty,因为最初的时候,Xshell登陆会被拒绝. 0. 创建个人文件夹 # 使用 yum 安装tomc ...

  7. Why does yum return error: [Errno 256] No more mirrors to try ?

    https://access.redhat.com/solutions/203603 ISSUE yum update fails with the error : [Errno 256] No mo ...

  8. http://blog.csdn.net/majian_1987/article/details/44939911

    http://blog.csdn.net/majian_1987/article/details/44939911

  9. 编码识别工具:hash-identifier

    hash-identifier的使用: 当不知道编码是什么类型的时候,可以通过kali系统中的hash工具判别,如下图所示, 在HASH后面输入要判别的编码内容,在后面的Possible Hashs中 ...

  10. 【今日推荐】10大流行的 Metro UI 风格的 Bootstrap 主题和模板

    1. BootMetro 基于 Twitter Bootstrap 的简单灵活的 HTML.CSS 和 Javascript 框架,Win8 风格,大爱啊! 立即下载     效果演示 2. Boot ...