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. cogs 2752. [济南集训 2017] 数列运算

    2752. [济南集训 2017] 数列运算 ★★☆   输入文件:sequenceQBXT.in   输出文件:sequenceQBXT.out   简单对比时间限制:1 s   内存限制:512 ...

  2. 【MFC设置静态文本框背景为透明】

    视图类中加入OnCtlColor()函数: IDC_STATIC1为静态文本框ID HBRUSH CAngleView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT n ...

  3. 1)Win10-UWA开发 UWP应用操作方法、Windows 10应用程序的指南

    孙广东   2015.8.22 全部任务类型(比方在列表中显示数据或创建导航窗格)的说明和代码演示样例. 在这一节 包含例如以下: 主题 描写叙述 Accessibility 创建通用的Windows ...

  4. app-framework学习--nav的Scroller禁用与启用

    app-framewor(jqmobi) nav的Scroller禁用与启用 写在panel 的 data-load 方法里 禁用  $.ui.scrollingDivs.menu_scroller. ...

  5. kentico version history and upgrade

    Version history Kentico 10: November 30, 2016 Kentico 9: November 24, 2015 Kentico 8.2: January 6, 2 ...

  6. js中callback执行

    <!DOCTYPE HTML> <html> <head> <meta charset="GBK" /> <title> ...

  7. m_Orchestrate learning system---十六、如何快速在一堆字符图标中找到所需

    m_Orchestrate learning system---十六.如何快速在一堆字符图标中找到所需 一.总结 一句话总结:find查找字符 比如说找teacher feedback 的图标,可以多 ...

  8. vim 按照字段排序文件

    假设有如下数据,以空格为数据列分割: 1  何维川   124.63     172  0.72 2  张子寅   99.67      172  0.58 3  周广滨   93.34      1 ...

  9. Pyinstaller 0

    Pyinstaller 是一个小的可以打包我们所写的Python脚本,来生成相应的可执行文件. 它是怎么工作的? PyInstaller读取您编写的Python脚本.它会分析您的代码,以发现您的脚本执 ...

  10. python的数据类型转换

    #编码:#py3中只有2种数据类型:str , bytes# str: unicode形式# bytes: 16进制 (更底层) 有utf8,gbk,gb2312 等等类型 #s='hi 范' # 编 ...