HDU4614 Vases and Flowers
http://acm.hdu.edu.cn/showproblem.php?pid=4614
HDU 4614 Vases and Flowers (2013多校第二场线段树)
// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int MOD = 1e9+;
#define LL long long
#define mi() (l+r)>>1
double const pi = acos(-);
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
struct Edge {
int l,r;
int lazy,sum;
} e[N<<]; void pushdown(int rt) {
e[rt].sum=e[rt<<].sum+e[rt<<|].sum;
}
void pushup(int rt) {
if(e[rt].lazy!=-) {
e[rt<<].lazy=e[rt<<|].lazy=e[rt].lazy;
e[rt<<].sum=(e[rt<<].r-e[rt<<].l+)*e[rt].lazy;
e[rt<<|].sum=(e[rt<<|].r-e[rt<<|].l+)*e[rt].lazy;
e[rt].lazy=-;
}
} void build(int l,int r,int rt) {
e[rt].l=l;
e[rt].r=r;
e[rt].lazy=-;
if(l==r) {
e[rt].sum=;
return;
}
int mid=mi();
build(lson);
build(rson);
pushdown(rt);
} int query(int l,int r,int rt) {
if(e[rt].l==l&&e[rt].r==r) {
return e[rt].sum;
}
pushup(rt);
int mid=(e[rt].l+e[rt].r)>>;
if(r<=mid) return query(l,r,rt<<);
else if(l>mid) return query(l,r,rt<<|);
else return query(l,mid,rt<<)+query(mid+,r,rt<<|);
} void update(int l,int r,int rt,int c){
if(e[rt].l==l&&e[rt].r==r){
e[rt].lazy=c;
e[rt].sum=(e[rt].r-e[rt].l+)*c;
return;
}
pushup(rt);
int mid=(e[rt].l+e[rt].r)>>;
if(r<=mid) update(l,r,rt<<,c);
else if(l>mid) update(l,r,rt<<|,c);
else {
update(l,mid,rt<<,c);
update(mid+,r,rt<<|,c);
}
pushdown(rt);
} int main() {
// fre();
int T;
scanf("%d",&T);
while(T--) {
int n,q;
cin>>n>>q;
build(,n,);
while(q--) {
int op,a,b;
cin>>op>>a>>b;
if(op==) {
int L=a+,R=n;
int st,ed;
if((n-L+-query(L,n,))==) {
printf("Can not put any one.\n");
continue;
}
st=inf;
while(L<=R) {
int mid=(L+R)>>;
if((mid-(a+)+-query(a+,mid,))>=) {
st=min(st,mid);
R=mid-;
} else {
L=mid+;
}
}
int tem=n-st+-query(st,n,);
if(tem<b) b=tem;
ed=inf;
L=st,R=n;
while(L<=R) {
int mid=(L+R)>>;
tem=mid-st+-query(st,mid,);
if(tem==b) {
ed=min(ed,mid);
R=mid-;
} else if(tem>b) {
R=mid-;
} else {
L=mid+;
}
}
printf("%d %d\n",st-,ed-);
update(st,ed,,);
} else {
printf("%d\n",query(a+,b+,));
update(a+,b+,,);
}
}
cout<<endl;
}
return ;
}
HDU4614 Vases and Flowers的更多相关文章
- hdu4614 Vases and Flowers 线段树
Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N ...
- hdu4614 Vases and Flowers【线段树】【二分】
Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N ...
- HDU-4614 Vases and Flowers(线段树区间更新+二分查找)
http://acm.hdu.edu.cn/showproblem.php?pid=4614 Time Limit: 4000/2000 MS (Java/Others) Memory Limi ...
- HDU-4614 Vases and Flowers (线段树区间更新)
题目大意:有n个花瓶,每个花瓶中只能放一朵花.两种操作,一种是从A开始放F朵花,如果有的花瓶中已经有花则跳过这个花瓶,往下一个花瓶放:第二种是将区间[A,B]之间花瓶中的花清空.如果是第一种操作,输出 ...
- HDU4614 Vases and Flowers 二分+线段树
分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小 #include<iostream> #include<cmath> #includ ...
- HDU-4614 Vases and Flowers 线段树区间更新
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 线段树保存区间是否被覆盖以及区间的和即可,在询问的时候在线段树上二分查找就可以了...代码写得比 ...
- hdu4614 Vases and Flowers 线段树+二分
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 题意: 给你N个花瓶,编号是0 到 N - 1 ,初始状态花瓶是空的,每个花瓶最多插一朵花. ...
- 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 ...
- 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 4101
比赛的时候先是受以前一个圣神海的题目 用了两遍DFS 第一遍标记出围墙 第二遍求围墙外和每块围墙降为1所需的攻击次数 结果爆栈 改为BFS后AC DFS的加了一句这个 #pragma comme ...
- codeforces #313 div1 C
同BZOJ 3782 上学路线 QAQ 还比那个简单一点 把坐标(1,1)-(n,m)平移成(0,0)-(n-1,m-1) 设dp[i]表示从(1,1)出发第一次经过障碍且到达第i个障碍的方案数 首先 ...
- POJ1753——Flip Game
Flip Game Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on ...
- dup和dup2函数以及管道的实现
疑问:管道应该不是这样实现的,因为这要求修改程序的代码 dup和dup2也是两个非常有用的调用,它们的作用都是用来复制一个文件的描述符.它们经常用来重定向进程的stdin.stdout和stderr. ...
- 关于hadoop的环境变量
export PATH export JAVA_HOME=/opt/jdk1.7 export PATH=$PATH:$JAVA_HOME/bin 为什么/etc/profile 添加了环境变量had ...
- Linux C/C++ 编程练手 --- 大数相加和大数相乘
最近写了一个大数相乘和相加的程序,结果看起来是对的.不过期间的效率可能不是最好的,有些地方也是临时为了解决问题而直接写出来的. 可以大概说一下相乘和相加的解决思路(当然,大数操作基本就是两个字符串的操 ...
- POJ3608(旋转卡壳--求两凸包的最近点对距离)
题目:Bridge Across Islands 分析:以下内容来自:http://blog.csdn.net/acmaker/article/details/3178696 考虑如下的算法, 算法的 ...
- python操作Excel读--使用xlrd
一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境. 二.使用介绍 1.导入模块 import x ...
- 第三部分 overlay 学习
前文仅了解了overlay HAL的架构,下面继续看看系统层是如何调用Overlay模块. 1.测试代码 frameworks/base/libs/surfaceflinger/tests/overl ...
- git恢复被修改的文件
恢复到最后一次提交的改动: git checkout -- + 需要恢复的文件名 但是,需要注意的是,如果该文件已经 add 到暂存队列中,上面的命令就不灵光喽 需要先让这个文件取消暂存: git r ...