Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N-1. When she receive some flowers, she will try to put them in the vases, one flower in one vase. She randomly choose the vase A and try to put a flower in the vase. If the there is no flower in the vase, she will put a flower in it, otherwise she skip this vase. And then she will try put in the vase A+1, A+2, ..., N-1, until there is no flower left or she has tried the vase N-1. The left flowers will be discarded. Of course, sometimes she will clean the vases. Because there are too many vases, she randomly choose to clean the vases numbered from A to B(A <= B). The flowers in the cleaned vases will be discarded.

题意:有 0~n-1 共 n 个花瓶,一个花瓶可以插一束花,现在有两个操作,一个是从 A 号花瓶开始插 k 束花,若花瓶有花就顺延到下一个花瓶,直到插完 k 束花或插完 n-1 号花瓶,问她插的第一个和最后一个花瓶编号。第二个操作是清空一段区间的花,问共丢掉多少花。

线段树保存区间空瓶数、首个空瓶和末个空瓶。树上二分查找 k 个空瓶,并更新最大最小空瓶位置。区间清除。

 #include<stdio.h>
#include<string.h>
const int maxm=;
const int INF=0x3f3f3f3f; int st[maxm<<],ma[maxm<<],mi[maxm<<];
int ch[maxm<<];
int maxx,minn,k; inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;} void build(int o,int l,int r){
ma[o]=r;
mi[o]=l;
st[o]=r-l+;
ch[o]=;
if(l==r)return;
int m=l+((r-l)>>);
build(o<<,l,m);
build(o<<|,m+,r);
} void pushdown(int o,int l,int r){
if(ch[o]==){
ch[o<<]=ch[o<<|]=;
int m=l+((r-l)>>);
st[o<<]=st[o<<|]=;
ma[o<<]=ma[o<<|]=-;
mi[o<<]=mi[o<<|]=INF;
ch[o]=;
}
else if(ch[o]==){
ch[o<<]=ch[o<<|]=;
int m=l+((r-l)>>);
st[o<<]=m-l+;
st[o<<|]=r-m;
ma[o<<]=m;
ma[o<<|]=r;
mi[o<<]=l;
mi[o<<|]=m+;
ch[o]=;
}
} void update1(int o,int l,int r,int ql,int qr){
if(ql<=l&&qr>=r){
if(k>=st[o]){
k-=st[o];
maxx=max(maxx,ma[o]);
minn=min(minn,mi[o]);
ma[o]=-;
mi[o]=INF;
st[o]=;
ch[o]=;
return;
}
else if(l==r)return;
}
pushdown(o,l,r);
int m=l+((r-l)>>);
if(ql<=m&&k)update1(o<<,l,m,ql,qr);
if(qr>=m+&&k)update1(o<<|,m+,r,ql,qr);
ma[o]=max(ma[o<<],ma[o<<|]);
mi[o]=min(mi[o<<],mi[o<<|]);
st[o]=st[o<<]+st[o<<|];
} int update2(int o,int l,int r,int ql,int qr){
if(ql<=l&&qr>=r){
int ans=r-l+-st[o];
st[o]=r-l+;
ma[o]=r;
mi[o]=l;
ch[o]=;
return ans;
}
pushdown(o,l,r);
int m=l+((r-l)>>);
int ans=;
if(ql<=m)ans+=update2(o<<,l,m,ql,qr);
if(qr>=m+)ans+=update2(o<<|,m+,r,ql,qr);
ma[o]=max(ma[o<<],ma[o<<|]);
mi[o]=min(mi[o<<],mi[o<<|]);
st[o]=st[o<<]+st[o<<|];
return ans;
} int main(){
int T;
scanf("%d",&T);
while(T--){
int n,m;
scanf("%d%d",&n,&m);
build(,,n-);
for(int i=;i<=m;++i){
int t;
scanf("%d",&t);
if(t==){
int a;
scanf("%d%d",&a,&k);
maxx=-;
minn=INF;
update1(,,n-,a,n-);
if(maxx==-&&minn==INF)printf("Can not put any one.\n");
else printf("%d %d\n",minn,maxx);
}
else if(t==){
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",update2(,,n-,a,b));
}
}
printf("\n");
}
return ;
}

hdu4614 Vases and Flowers 线段树的更多相关文章

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

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

  2. hdu4614 Vases and Flowers 线段树+二分

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 题意: 给你N个花瓶,编号是0  到 N - 1 ,初始状态花瓶是空的,每个花瓶最多插一朵花. ...

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

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

  4. hdu 4614 Vases and Flowers 线段树

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

  5. hdu4614 Vases and Flowers【线段树】【二分】

    Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N ...

  6. HDU-4614 Vases and Flowers(线段树区间更新+二分查找)

    http://acm.hdu.edu.cn/showproblem.php?pid=4614 Time Limit: 4000/2000 MS (Java/Others)    Memory Limi ...

  7. HDU-4614 Vases and Flowers (线段树区间更新)

    题目大意:有n个花瓶,每个花瓶中只能放一朵花.两种操作,一种是从A开始放F朵花,如果有的花瓶中已经有花则跳过这个花瓶,往下一个花瓶放:第二种是将区间[A,B]之间花瓶中的花清空.如果是第一种操作,输出 ...

  8. HDU4614 Vases and Flowers 二分+线段树

    分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小 #include<iostream> #include<cmath> #includ ...

  9. HDU4614 Vases and Flowers

    http://acm.hdu.edu.cn/showproblem.php?pid=4614 HDU 4614 Vases and Flowers (2013多校第二场线段树) // #pragma ...

随机推荐

  1. linux磁盘管理 文件挂载

    文件挂载的概念 根文件系统之外的其他文件要想能够被访问,都必须通过"关联"到根文件系统上的某个系统来实现,此关联操作即为"挂载",此目录即为"挂载点& ...

  2. Spring框架基本代码

    1.准备阶段: 2.基本引入: 接口: package com.xk.spring.kp01_hello; public interface IHello { public void nice(); ...

  3. POST提交表单时EnType设置问题

    POST提交表单时EnType设置问题 首先知道enctype这个属性管理的是表单的MIME编码.共有三个值可选: 1.application/x-www-form-urlencoded 2.mult ...

  4. 删除Mac OS X中Finder文件打开方式列表的重复程序或失效的

    清理列表, 可以在终端中输入下面提供的一行命令: /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices ...

  5. 第三篇 功能实现(1) (Android学习笔记)

    第三篇 功能实现(1) 第8章 Android应用程序组成 ●Android的一些中.底层基础知识 ※ Android Framework 启动过程 Android手机系统本质上是一个基于Linux的 ...

  6. VBA续嘘嘘——宏技巧集绵

    什么是VBA?它有什么作用? A.实现Excel中没有实现的功能. B.提高运行速度. C.编写自定义函数. D.实现自动化功能. E.通过插入窗体做小型管理软件. VBA在哪里存放的?怎么运行? A ...

  7. python中的argparse模块(参数解析)

    import argparseparse = argparse.ArgumentParser()parse.add_argument("a", help="params ...

  8. ArrayList和LinkedList有什么区别?

    ---恢复内容开始--- ArrayList和LinkedList都实现了List接口,但是: ArrayList是基于索引的数据接口,底层是数组,能够以O(1)时间复杂度随机访问元素.而Linked ...

  9. Win10安装mysql-8.0.11-winx64详细步骤

    安装 mysql-8.0.11-winx64 https://blog.csdn.net/qq_20788055/article/details/80372577

  10. windows消息传送(自定义消息和WM_COPYDATA)

    通过SendMessge实现的进程间通信. 0x01 自定义消息 1,WINDOWS中自定义消息的定义和使用: (1)在WNDOWS中消息分系统消息和自定义消息.系统消息定义从0到0x3FF,使用0x ...