11946317 2014-10-23 09:08:28 Accepted 4614 437MS 2348K

rid=11946317" target="_blank" style="color:rgb(26,92,200); text-decoration:none">3340 B

G++

KinderRiven

#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
/********************************
KinderRiven
*******************************/
#define lson (pos<<1)
#define rson (pos<<1|1)
const int maxn = 55555;
struct Node{
int l,r;
int v,col;
}node[maxn << 2];
int N,M;
void pushdown(int pos){
if(node[pos].col >= 0){
node[lson].col = node[pos].col; node[rson].col = node[pos].col;
node[lson].v = (node[lson].r - node[lson].l + 1) * node[pos].col;
node[rson].v = (node[rson].r - node[rson].l + 1) * node[pos].col;
node[pos].col = -1;
}
}
void pushup(int pos){
node[pos].v = node[lson].v + node[rson].v;
}
void BuildTree(int L,int R,int pos){
node[pos].l = L;
node[pos].r = R;
node[pos].col= -1;
if(L == R){
node[pos].v = 1;
return;
}
int m = (L + R) >> 1;
BuildTree(L,m,lson);
BuildTree(m + 1,R,rson);
pushup(pos);
return;
}
void UpDate(int L,int R,int pos,int value){
//printf("%d %d\n",node[pos].l,node[pos].r);
if(L <= node[pos].l && node[pos].r <= R){
node[pos].v = (node[pos].r - node[pos].l + 1) * value;
node[pos].col = value;
return;
}
pushdown(pos);
int m = (node[pos].l + node[pos].r) >> 1;
if(L <= m)
UpDate(L,R,lson,value);
if(R > m)
UpDate(L,R,rson,value);
pushup(pos);
}
int Query_sum(int L,int R,int pos){
if(L <= node[pos].l && node[pos].r <= R){
return node[pos].v;
}
pushdown(pos);
int m = (node[pos].l + node[pos].r) >> 1;
int ret = 0;
if(L <= m)
ret += Query_sum(L,R,lson);
if(R > m)
ret += Query_sum(L,R,rson);
pushup(pos);
return ret;
}
void Query(int value,int pos,int &p){
if(node[pos].l == node[pos].r){
p = node[pos].l;
return;
}
pushdown(pos);
int m = (node[pos].l + node[pos].r) >> 1;
if(node[lson].v >= value)
Query(value,lson,p);
else
Query(value - node[lson].v,rson,p);
pushup(pos);
return;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&N,&M);
BuildTree(0,N - 1,1);
int op,a,b;
for(int i = 0;i < M;i ++){
scanf("%d%d%d",&op,&a,&b);
//printf("%d\n",Query_sum(0,N-1,1));
if(op == 1){ //须要改动
int sum = Query_sum(0,N - 1,1);
int k1 = Query_sum(a,N - 1,1);
int v = sum - k1;
//printf("%d\n",k1);
int p,q;
if(k1 == 0){
printf("Can not put any one.\n");
continue;
}
if(k1 < b) b = k1;
Query(v + 1,1,p);
Query(v + b,1,q);
UpDate(p,q,1,0);
printf("%d %d\n",p,q);
}
else if(op == 2){
int value = Query_sum(a,b,1);
UpDate(a,b,1,1);
printf("%d\n",b - a + 1 - value);
}
}
printf("\n");
}
return 0;
}

【HDU-4614】Vases and Flowers(线段树双查询)的更多相关文章

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

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

  2. hdu 4614 Vases and Flowers 线段树

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

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

    Vases and Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others ...

  4. 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 ...

  5. HDU 4614 Vases and Flowers(二分+线段树区间查询修改)

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

  6. HDU 4614 Vases and Flowers(线段树+记录区间始末点或乱搞)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 题目大意:有n个空花瓶,有两种操作: 操作①:给出两个数字A,B,表示从第A个花瓶开始插花,插B ...

  7. hdu 4614 Vases and Flowers(线段树:成段更新)

    线段树裸题.自己写复杂了,准确说是没想清楚就敲了. 先是建点为已插花之和,其实和未插花是一个道理,可是开始是小绕,后来滚雪球了,跪了. 重新建图,分解询问1为:找出真正插画的开始点和终止点,做成段更新 ...

  8. HDU 4614 Vases and Flowers (2013多校第二场线段树)

    题意摘自:http://blog.csdn.net/kdqzzxxcc/article/details/9474169 ORZZ 题意:给你N个花瓶,编号是0 到 N - 1 ,初始状态花瓶是空的,每 ...

  9. HDU 4614 Vases and Flowers 【线段树】+【二分】

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

  10. hdu 4614 Vases and Flowers

    http://acm.hdu.edu.cn/showproblem.php?pid=4614 直接线段树维护 代码: #include<iostream> #include<cstd ...

随机推荐

  1. POJ 1185 炮兵阵地 (状压dp)(棋盘dp)

    这题和poj 3254很像,但是更复杂了一些 都属于棋盘里放东西,然后又各种各样的限制,然后求方案或者最大值 (1)上一道题距离要大于1,这道题是大于2.所以判断的时候变成 !(x & (x ...

  2. [luogu]P3572 [POI2014]PTA-Little Bird(单调队列)

    P3572 [POI2014]PTA-Little Bird 题目描述 In the Byteotian Line Forest there are nn trees in a row. On top ...

  3. 2015 Multi-University Training Contest 7 hdu 5379 Mahjong tree

    Mahjong tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  4. 洛谷 1063 dp 区间dp

    洛谷 1063 dp 区间dp 感觉做完这道提高组T1的题之后,受到了深深的碾压,,最近各种不在状态.. 初看这道题,不难发现它具有区间可并性,即(i, j)的最大值可以由(i, k) 与 (k+1, ...

  5. Qt之设置应用程序图标

    简述 应用程序图标,通常显示在应用程序的顶层窗口的左上角,通过调用QWindow:setWindowIcon()函数来实现. 为了改变可执行程序文件本身的图标,因为它被呈现在桌面上,它必须采用另一种依 ...

  6. PyQt: LineEdit的智能输入提示

    使用的的类是QtGui.QCompleter from PyQt4 import QtGui,QtCore str = QtCore.QStringList(['a','air','airbus']) ...

  7. 从ORA-27300,ORA-27301到ORA-00064

        近期因为session数量添加,须要调整session,也就是要调整process參数. 看是比較简单的一个问题,却遭遇了ORA-27300,ORA-27301.因为这个涉及到了有关内核參数k ...

  8. js小结2

    1.includes和contains 对于字符串,数组来说,判断包含是includes,对classList是contains 2.编辑span内容,enter提交(如何避免keydown之后换行: ...

  9. JS基本功 | JavaScript专题之数组 - 方法总结

    Array.map() 1.   map() 遍历数组 语法: let new_array = arr.map(function callback(currentValue, index, array ...

  10. 关于PageRank的总结

    好久不用CSDN,最近想给带的本科生实验课开个期末习题专题页,发现CSDN的博客忽然要绑定之类.只好弃用回博客园写学习总结了.塞翁失马焉知非福. *************************** ...