tjut 4614
来源:互联网 发布:程序员看的书 活着 编辑:程序博客网 时间:2024/06/06 17:14
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 50100 #define lson (pos<<1) #define rson (pos<<1|1) struct node { int l,r,tag,sum; } tree[N*4]; void build(int pos, int l, int r) { tree[pos].l=l; tree[pos].r=r; tree[pos].tag=0; tree[pos].sum=r-l+1; if(l==r)return ; int mid=(l+r)/2; build(lson,l,mid); build(rson,mid+1,r); } void pushdown(int pos) { if(tree[pos].tag) { if(tree[pos].tag==2) { tree[lson].sum=(tree[lson].r-tree[lson].l+1); tree[lson].tag=2; tree[rson].sum=(tree[rson].r-tree[rson].l+1); tree[rson].tag=2; tree[pos].tag=0; } else { tree[lson].sum=0; tree[lson].tag=1; tree[rson].sum=0; tree[rson].tag=1; tree[pos].tag=0; } } } void pushup(int pos) { tree[pos].sum=tree[lson].sum+tree[rson].sum; } void update(int pos, int L, int R, int v) { if(L<=tree[pos].l&&tree[pos].r<=R) { if(v==1) { tree[pos].tag=1; tree[pos].sum=0; } else if(v==2) { tree[pos].tag=2; tree[pos].sum=tree[pos].r-tree[pos].l+1; } return ; } pushdown(pos); int mid=(tree[pos].l+tree[pos].r)/2; if(L<=mid)update(lson,L,R,v); if(mid<R)update(rson,L,R,v); pushup(pos); } int query(int pos, int L, int R) { if(L<=tree[pos].l&&tree[pos].r<=R) { return tree[pos].sum; } pushdown(pos); int mid=(tree[pos].l+tree[pos].r)/2; int ans=0; if(L<=mid)ans+=query(lson,L,R); if(mid<R)ans+=query(rson,L,R); return ans; } int main() { int T; scanf("%d",&T); while(T--) { int n,m; scanf("%d%d",&n,&m); build(1,1,n); for(int i = 0; i < m; i++) { int id; scanf("%d",&id); if(id==1) { int A,B; int s, w; scanf("%d%d",&s,&w); s++; int sum=query(1,s,n); sum=min(w,sum); if(sum==0) { printf("Can not put any one.\n"); continue; } int l=s,r=n; if(sum==1) { if(query(1,l,l)) { A=l; B=l; printf("%d %d\n",A-1,B-1); update(1,A,B,1); continue; } } sum--; //printf("sum=%d\n",sum); while(l+1<r) { int mid=(l+r)/2; int tmp=query(1,s,mid); //printf("mid=%d tmp=%d l=%d r=%d\n",mid,tmp,l,r); if(tmp>sum)r=mid; else l=mid; } B=r; l=s; r=B; if(sum==0) { if(query(1,r,r)) { A=r; B=r; printf("%d %d\n",A-1,B-1); update(1,A,B,1); continue; } } while(l+1<r) { int mid=(l+r)/2; int tmp=query(1,mid,B); if(tmp>sum)l=mid; else r=mid; } A=l; printf("%d %d\n",A-1,B-1); update(1,A,B,1); } else if(id==2) { int a,b; scanf("%d%d",&a,&b); a++; b++; int hehe=b-a+1-query(1,a,b); printf("%d\n",hehe); if(hehe!=0) update(1,a,b,2); } } printf("\n"); } return 0; }
0 0
- tjut 4614
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- GitHub上那些值得一试的JAVA开源库
- bzoj 1588: [HNOI2002]营业额统计 splay
- singleTop和singleTask
- 16进制颜色值
- MySql的触发器
- tjut 4614
- JOGL2.3在Eclipse里面的配置
- JVM内存回收之finalize()方法
- 整理:STL sort排序算法详细介绍
- TCP/IP——socket网络编程总结
- HTML学习04-HTML文本格式化
- 线程同步,锁的相关问题
- Java面向对象
- C# 值不能为null,参数名:name 【已经解决】