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 ...
随机推荐
- What the hell is Rotate?
- CrackMe_001
本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注册机的东西. 其中,文章中按照如下逻辑编排(解决如 ...
- uva 147
一个简单的dp 面值是5的倍数 将面值都除5 因为输出问题wa .... #include <iostream> #include <cstring> #includ ...
- Samza文档翻译 : Concepts
此页介绍啊Samza的一些高层级概念. Streams Samza处理Streams(流).流由同一类型的不可变的消息组成.例如,一个流可以是对一个网站的所有点击,或者对一个数据库表的所有更新,或者一 ...
- IDEA 运行maven命令时报错: -Dmaven.multiModuleProjectDirectory system propery is not set
在file-setting里面,找到maven的设置: 先加入一个环境变量 然后配置一个JVM的参数: -Dmaven.multiModuleProjectDirectory=$M2_HOME OK ...
- WebLoigc的配置(生产模式与开发模式)
1.Weblogic两种模式的切换1).生产模式--->开发模式将domain路径下的bin\setDomainEnv.cmd文件中set PRODUCTION_MODE=true改为set P ...
- uEditor独立图片上传
项目中.上传图片,非常希望有一款比较兼容的查件. 网上找了一些,图片上传立刻显示的js代码,还有uploadify.都会碰到这样那样的不兼容和其它头疼的问题. 后来想,干脆就用php的上传类最干脆.但 ...
- ZOJ1204——Additive equations(DFS)
Additive equations Description We all understand that an integer set is a collection of distinct int ...
- Android 自绘TextView解决提前换行问题,支持图文混排
先看下效果图: 上面是MTextView,下面是默认的TextView. 一.原因 用最简单的全英文句子为例,如果有一个很长的单词,这一行剩余的空间显示不下了,那么规则就是不打断单词,而是把整个单词丢 ...
- P127、面试题20:顺时针打印矩阵
题目:输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字.例如:如果输入如下矩阵:1 2 3 4 5 6 7 89 10 11 1213 14 15 16则依次打印出 ...