HDU 4614
来源:互联网 发布:淘宝上买到假货仅退款 编辑:程序博客网 时间:2024/06/06 07:14
/*HDU 4614Vases and Flowers二分 + 线段树*/#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define lson (pos<<1)#define rson (pos<<1|1)const int maxn = 55555;int n,m,pos_x,pos_y;struct Node{ int l,r,col,cover; int mid(){ return (l + r) >> 1; } int len(){ return (r - l + 1); }}node[maxn << 2];void pushup(int pos){ node[pos].cover = node[lson].cover + node[rson].cover;}void pushdown(int pos){ if(node[pos].col != -1){ node[lson].cover = node[lson].len() * node[pos].col; node[lson].col = node[pos].col; node[rson].cover = node[rson].len() * node[pos].col; node[rson].col = node[pos].col; node[pos].col = -1; }}void build(int l,int r,int pos){ node[pos].col = -1; node[pos].l = l; node[pos].r = r; if(l == r){ node[pos].cover = 1; return; } int mid = (l + r) >> 1; build(l,mid,lson); build(mid + 1,r,rson); pushup(pos);}void update(int l,int r,int pos,int d){ if(l <= node[pos].l && node[pos].r <= r){ node[pos].cover = d * node[pos].len(); node[pos].col = d; return; } pushdown(pos); int mid = node[pos].mid(); if(l <= mid) update(l,r,lson,d); if(r > mid) update(l,r,rson,d); pushup(pos); return;}int query(int l,int r,int pos,int op){ if(l <= node[pos].l && node[pos].r <= r){ if(op == 0) return node[pos].len() - node[pos].cover; else return node[pos].cover; } int mid = node[pos].mid(); pushdown(pos); int ans = 0; if(l <= mid) ans += query(l,r,lson,op); if(r > mid) ans += query(l,r,rson,op); pushup(pos); return ans;}void solve(int x,int y){ int t = query(x,n - 1,1,1); if(t == 0){ printf("Can not put any one.\n"); return; } if(t < y) y = t; int l = x, r = n - 1,mid; while(l <= r){ mid = (l + r) >> 1; int v = query(x,mid,1,1); if(v >= y){ pos_y = mid; r = mid - 1; } else l = mid + 1; } l = x; r = pos_y; while(l <= r){ mid = (l + r) >> 1; int v = query(mid,pos_y,1,1); if(v >= y){ pos_x = mid; l = mid + 1; } else r = mid - 1; } printf("%d %d\n",pos_x,pos_y); update(pos_x,pos_y,1,0); return;}int main(){ int T,op,x,y;; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); build(0,n - 1,1); for(int i = 0; i < m; i++){ scanf("%d",&op); scanf("%d%d",&x,&y); if(op == 1){ solve(x,y); } else{ printf("%d\n",query(x,y,1,0)); update(x,y,1,1); } } puts(""); } return 0;}
0 0
- HDU 4614
- hdu 4614
- HDU 4614
- hdu 4614 线段树
- hdu 4614 (线段树)
- Hdu 4614 线段树
- HDU 4614(线段树)
- hdu 4614(区间更新)
- HDU 4614 (线段树)
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- javac: target release 1.5 conflicts with default source release 1.7
- 爽爆天的shell - zsh - 基于“Oh-My-Zsh”
- 在WindForm中绑定DataGridView
- jfinal操作json
- JPA入门例子(采用JPA的hibernate实现版本)
- HDU 4614
- ios app 应用内购买配置完全指南
- 这就是自己的第一篇博客吧,随便聊聊
- 判断IP地址是否正确
- 微信开发(八)自动回复和多客服开发
- 可变参数
- MYSQL 的主主同步配置及问题
- Linux程序崩溃(segment fault)原因的调试
- intellij idea14 +tomcat7 ssh2 启动项目失败解决办法