poj 3667
来源:互联网 发布:nodejs nginx 部署 编辑:程序博客网 时间:2024/06/05 15:04
线段树区间合并什么的。。。
#include<map>#include<string>#include<cstdio>#include<cstdlib>#include<cstring>#include<ctime>#include<cmath>#include<iostream>#include<algorithm>const int MAXN = 50005;int n , m;struct treenode{ int lmax,rmax,mmax; int col;}tree[MAXN<<2] = {0};#define L(x) (x<<1)#define R(x) ((x<<1)|1)void pushdown(int x,int ll,int rr){ if(tree[x].col != -1) { int mid = (ll+rr)>>1; tree[L(x)].lmax = tree[L(x)].rmax = tree[L(x)].mmax = (mid-ll+1)*(tree[x].col^1); tree[R(x)].lmax = tree[R(x)].rmax = tree[R(x)].mmax = (rr - mid)*(tree[x].col^1); tree[L(x)].col = tree[R(x)].col = tree[x].col; tree[x].col = -1; }}void update(int x,int ll,int rr){ int mid = (ll+rr)>>1; tree[x].mmax = std::max(std::max(tree[L(x)].mmax,tree[R(x)].mmax),tree[L(x)].rmax + tree[R(x)].lmax); tree[x].lmax = tree[L(x)].lmax + ((tree[L(x)].lmax == mid-ll+1)?tree[R(x)].lmax:0); tree[x].rmax = tree[R(x)].rmax + ((tree[R(x)].rmax == rr - mid)?tree[L(x)].rmax:0);}void color(int l,int r,int ll,int rr,int si,int col){ if(ll == l && rr == r) { tree[si].col = col; tree[si].mmax = (rr-ll+1)*(col^1); tree[si].lmax = tree[si].rmax = tree[si].mmax ; } else { int mid = (ll+rr)>>1; pushdown(si,ll,rr); if(r<=mid) color(l,r,ll,mid,L(si),col); else if(l>mid)color(l,r,mid+1,rr,R(si),col); else { color(l,mid,ll,mid,L(si),col); color(mid+1,r,mid+1,rr,R(si),col); } update(si,ll,rr); }}int query(int ll,int rr,int si,int len){ int mid = (ll+rr)>>1; pushdown(si,ll,rr); if(len <= tree[L(si)].mmax) return query(ll,mid,L(si),len); else if(len <= tree[L(si)].rmax + tree[R(si)].lmax) return mid - tree[L(si)].rmax + 1; else return query(mid+1,rr,R(si),len);}#undef L#undef Rint main(){#ifndef ONLINE_JUDGE freopen("poj3667.in","r",stdin); freopen("poj3667.out","w",stdout);#endif scanf("%d%d",&n,&m); tree[1].col = 0 , tree[1].lmax = tree[1].rmax = tree[1].mmax = n; while(m--) { int tag;scanf("%d",&tag); if(tag == 1) { int len; scanf("%d",&len); if(len<=tree[1].mmax) { int st = query(1,n,1,len); printf("%d\n",st); color(st,st+len-1,1,n,1,1); } else puts("0"); } else { int a,b;scanf("%d%d",&a,&b); color(a,a+b-1,1,n,1,0); } }#ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout);#endif return 0;}
0 0
- poj 3667
- poj 3667
- poj 3667
- POJ 3667
- POJ 3667
- POJ 3667
- poj - 3667
- poj 3667
- (3667)POJ
- poj 3667
- POJ 3667
- poj 3667
- POJ 3667
- Poj 3667
- POJ 3667
- poj 3667 Hotel
- poj 3667 Hotel
- poj 3667 Hotel
- [github] github入手教程
- 设计模式之单例模式(C++)
- CountDownLatch的使用方法
- iphone常用控件之UIScrollView
- IOS中NSUserDefaults的用法(轻量级本地数据存储)
- poj 3667
- 队列
- 最大公约数和最小公倍数
- 对C++中派生类的认识
- 字符串分割(C++)
- java 反射通过get方法获得属性值
- Leetcode: Maximum Product Subarray
- 关于单例模式的一点思考
- 谈谈小米4的win10---一个windows phone 用户2年的瞎扯