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 ...
随机推荐
- 使用Web代理实现Ajax跨域
目前的工作项目分为前端和后台,双方事先约定接口,之后独立开发.后台每天开发完后在测试服务器上部署,前端连接测试服务器进行数据交互.前端和后台分开的好处是代码不用混在一个工程里一起build,互不干涉. ...
- Java将整个文件夹里的文本中的字符串替换成另外一个字符串(可用于项目复制,变成另一个项目)
import org.junit.Test; import java.io.*; /** * User: HYY * Date: 13-8-18 * Time: 下午8:11 * To change ...
- 服务器部署_linux下部署jprofiler简单备忘
1.windows安装jprofiler 2.linux下安装jprofiler服务端,记好安装路径.假设是安装在/ex/bin/下 3. 配置tomcat的启动sh文件,在后面加入以下参数: -a ...
- HeadFirst设计模式之迭代器模式
一. 1.迭代器模式是对遍历集合元素的抽象 2.The Iterator Pattern provides a way to access the elements of an aggregate o ...
- Qt之界面数据存储与获取(使用setUserData()和userData())
在GUI开发中,往往需要在界面中存储一些有用的数据,这些数据可以来配置文件.注册表.数据库.或者是server. 无论来自哪里,这些数据对于用户来说都是至关重要的,它们在交互过程中大部分都会被用到,例 ...
- Android:使用ViewPager实现左右滑动切换图片(图上有点点)
在以下实例的基础上加上点点 Android:使用ViewPager实现左右滑动切换图片 (简单版) 效果预览: 因为要把点点放图片上,所以修改布局为相对布局: <?xml version=&qu ...
- Spring中的实例生成方式及其生命周期
三种实例化bean的方式1.使用类构造器实例化 <!-- 使用类构造器实例化,class属性表示要使用的类的全限定名 --> <bean id="userDao1" ...
- linux netcat命令
netcat是网络工具中的“瑞士军刀”,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它.使用netcat命令所能完成的事情令人惊讶. netcat所 ...
- objective-C 自定义对象归档的实现
自定义对象要实现归档必须实现NSCoding协议 NSCoding协议有两个方法,encodeWithCoder方法对对象的属性数据做编码处理,initWithCoder解码归档数据来初始化对象. # ...
- margin,border,padding简介
站在图中心 Content 的角度理解: margin为外边框,border为边框,padding为内边框. 在xml中设置: 如果上下左右的距离都是相同可以通过 android:layout_mar ...