HDU4614 Vases and Flowers 二分+线段树
分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=5e4+;
int n,m,T,c[N<<],lz[N<<];
void build(int rt,int l,int r){
lz[rt]=-;
if(l==r){c[rt]=;return;}
int m=(l+r)>>;
build(rt<<,l,m);
build(rt<<|,m+,r);
c[rt]=c[rt<<]+c[rt<<|];
}
void pushdown(int rt,int l,int r){
if(lz[rt]!=-){
int m=(l+r)>>;
c[rt<<]=lz[rt]*(m-l+);
c[rt<<|]=lz[rt]*(r-m);
lz[rt<<]=lz[rt<<|]=lz[rt];
lz[rt]=-;
}
}
int t;
void modify(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y){
c[rt]=t*(r-l+);
lz[rt]=t;
return;
}
int m=(l+r)>>;
pushdown(rt,l,r);
if(x<=m)modify(rt<<,l,m,x,y);
if(y>m)modify(rt<<|,m+,r,x,y);
c[rt]=c[rt<<]+c[rt<<|];
}
int ask(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y)return c[rt];
int m=(l+r)>>,ans=;
pushdown(rt,l,r);
if(x<=m)ans+=ask(rt<<,l,m,x,y);
if(y>m)ans+=ask(rt<<|,m+,r,x,y);
return ans;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
build(,,n);
while(m--){
int op,x,y;
scanf("%d%d%d",&op,&x,&y);
if(op==){
++x,++y;
printf("%d\n",y-x+-ask(,,n,x,y));
t=;modify(,,n,x,y);
continue;
}
++x;
y=min(y,ask(,,n,x,n));
if(!y){
printf("Can not put any one.\n");
continue;
}
int ans1,ans2;
int l=x,r=n;
while(l<r){
int mid=(l+r)>>,cur=ask(,,n,x,mid);
if(!cur)l=mid+;
else r=mid;
}
ans1=(l+r)>>;
l=x,r=n;
while(l<r){
int mid=(l+r)>>,cur=ask(,,n,x,mid);
if(cur<y)l=mid+;
else r=mid;
}
ans2=(l+r)>>;
t=;modify(,,n,ans1,ans2);
printf("%d %d\n",--ans1,--ans2);
}
printf("\n");
}
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 ...
- 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(二分+线段树区间查询修改)
描述Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to ...
- HDU-4614 Vases and Flowers (线段树区间更新)
题目大意:有n个花瓶,每个花瓶中只能放一朵花.两种操作,一种是从A开始放F朵花,如果有的花瓶中已经有花则跳过这个花瓶,往下一个花瓶放:第二种是将区间[A,B]之间花瓶中的花清空.如果是第一种操作,输出 ...
- HDU 4614 Vases and Flowers(线段树+二分)
Vases and Flowers Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others ...
- HDU 4614 Vases and Flowers 【线段树】+【二分】
<题目链接> 题目大意: 有n个花瓶,每个花瓶中只能放一朵花.两种操作,一种是从A开始放F朵花,如果有的花瓶中已经有花则跳过这个花瓶,往下一个花瓶放:第二种是将区间[A,B]之间花瓶中的花 ...
- 【HDU 4614】Vases and Flowers(线段树区间更新懒惰标记)
题目0到n-1的花瓶,操作1在下标a开始插b朵花,输出始末下标.操作2清空[a,b]的花瓶,求清除的花的数量.线段树懒惰标记来更新区间.操作1,先查询0到a-1有num个空瓶子,然后用线段树的性质,或 ...
- HDU4614Vases and Flowers 二分+线段树;
参考:https://blog.csdn.net/ophunter_lcm/article/details/9879495 题意: 有n个花瓶,有两种操作,1.从a开始放b朵花,有花的花瓶跳过,2 ...
- Vases and Flowers-HDU4614 二分+线段树
题意: 给你N个花瓶,编号是0 到 N - 1 ,一开始每个花瓶都是空的,你有两个操作: 第一个操作: 从第x个花瓶起开始插花,总共插y束,如果遇到花瓶中有花就跳过这个花瓶,直到花插完或者 插到第N ...
随机推荐
- 闭包(Closures)
浅析 JavaScript 中的闭包(Closures) 一.前言 对于 JavaScript 来说,闭包是一个非常强大的特征.但对于刚开始接触的初学者来说它又似乎是特别高深的.今天我们一起来揭开闭包 ...
- div蒙版+可移动
<html> <head> <title></title> <script src="jquery-1.8.2.js&q ...
- Contest2037 - CSU Monthly 2013 Oct (problem B :Scoop water)
http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=1 [题解]:卡特兰数取模 h(n) = h(n-1)*(4*n-2)/( ...
- 第三方登录过程—OAuth2.0协议
---恢复内容开始--- 理清思路 1.在第三方注册成为开发者,拿到第三方给的client_id(app_id---就像你的身份证.QQ号)和client_secret(就像你的QQ密码): 2.填写 ...
- PHP程序员函数注释规格
<?php/*** @name 名字* @abstract 申明变量/类/方法* @access 指明这个变量.类.函数/方法的存取权限* @author 函数作者的名字和邮箱地址* @cate ...
- C/C++中几种经典的垃圾回收算法
1.引用计数算法 引用计数(Reference Counting)算法是每个对象计算指向它的指针的数量,当有一个指针指向自己时计数值加1:当删除一个指向自己的指针时,计数值减1,如果计数值减为0,说明 ...
- 【无聊放个模板系列】BZOJ 1597 斜率优化
STL 双向队列DEQUE版本 #include<cstdio> #include<cstdlib> #include<cstring> #include<i ...
- BZOJ 2553 禁忌
首先我们要考虑给定一个串,如何将他划分,使得他有最多的禁忌串 我们只需要按里面出现的禁忌串们的出现的右端点排序然后贪心就可以啦 我们建出AC自动机,在AC自动机等价于走到一个包含禁忌串的节点就划分出一 ...
- Android:控件GridView的使用
如果是列表(单列多行形式)的使用ListView,如果是多行多列网状形式的优先使用GridView. <?xml version="1.0" encoding="u ...
- update多表陷阱
今天同学发了个sql题目 A1表 B1表 id num id snum 1 10 1 90 2 2000 3 4000 3 30 B表的数据插入A表当中 最后的结果 A表 1 90 2 2000 3 ...