Vases and Flowers
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
2 10 5 1 3 5 2 4 5 1 1 8 2 3 6 1 8 8 10 6 1 2 5 2 3 4 1 0 8 2 2 5 1 4 4 1 2 3
Sample Output
[pre]3 7 2 1 9 4 Can not put any one. 2 6 2 0 9 4 4 5 2 3 [/pre]
#include<cstring> #include<string> #include<iostream> #include<queue> #include<cstdio> #include<algorithm> #include<map> #include<cstdlib> #include<cmath> #include<vector> //#pragma comment(linker, "/STACK:1024000000,1024000000"); using namespace std; #define INF 0x3f3f3f3f #define maxn 210005 int sum[maxn]; int tag[maxn]; int lt[maxn]; int rt[maxn]; int ll[maxn],rr[maxn]; void init(int l,int r,int k) { sum[k]=r-l+1; tag[k]=0; lt[k]=l; rt[k]=r; ll[k]=l; rr[k]=r; if(l==r) return ; int mid=(l+r)>>1; init(l,mid,k<<1); init(mid+1,r,k<<1|1); } void pushdown(int k) { if(!tag[k]) return ; if(tag[k]==1) { tag[k<<1]=tag[k<<1|1]=1; lt[k<<1]=INF; rt[k<<1]=-INF; lt[k<<1|1]=INF; rt[k<<1|1]=-INF; sum[k<<1]=sum[k<<1|1]=0; } else { tag[k<<1]=tag[k<<1|1]=-1; lt[k<<1]=ll[k<<1]; rt[k<<1]=rr[k<<1]; lt[k<<1|1]=ll[k<<1|1]; rt[k<<1|1]=rr[k<<1|1]; sum[k<<1]=rr[k<<1]-ll[k<<1]+1; sum[k<<1|1]=rr[k<<1|1]-ll[k<<1|1]+1; } tag[k]=0; } void pushup(int k) { sum[k]=sum[k<<1]+sum[k<<1|1]; lt[k]=min(lt[k<<1],lt[k<<1|1]); rt[k]=max(rt[k<<1],rt[k<<1|1]); } int ans1,ans2; void update(int d,int l,int r,int s,int e,int k) { if(s==l&&r==e) { tag[k]=d; if(!ans1&<[k]!=INF) ans1=lt[k]; if(rt[k]!=-INF) ans2=rt[k]; if(d==1) { lt[k]=INF; rt[k]=-INF; sum[k]=0; } else { lt[k]=l; rt[k]=r; sum[k]=r-l+1; } return ; } pushdown(k); int mid=(s+e)>>1; if(r<=mid) update(d,l,r,s,mid,k<<1); else if(l>mid) update(d,l,r,mid+1,e,k<<1|1); else { update(d,l,mid,s,mid,k<<1); update(d,mid+1,r,mid+1,e,k<<1|1); } pushup(k); } int query(int l,int r,int s,int e,int k) { if(s==l&&e==r) { return sum[k]; } pushdown(k); int mid=(s+e)>>1; if(r<=mid) return query(l,r,s,mid,k<<1); else if(l>mid) return query(l,r,mid+1,e,k<<1|1); else { return query(l,mid,s,mid,k<<1)+query(mid+1,r,mid+1,e,k<<1|1); } } int main() { int T; scanf("%d",&T); while(T--) { int n,m; scanf("%d%d",&n,&m); init(1,n,1); while(m--) { int p; scanf("%d",&p); if(p==1) { int a,b; scanf("%d%d",&a,&b); a++; int l=a,r=n; while(l+1<=r) { int mid=(l+r)>>1; int temp=query(a,mid,1,n,1); if(temp<=b) l=mid+1; else r=mid-1; } int k; int temp=query(a,l,1,n,1); if(temp<=b) k=l; else k=l-1; temp=query(a,k,1,n,1); if(temp==0) { printf("Can not put any one.\n"); continue; } ans1=ans2=0; update(1,a,k,1,n,1); printf("%d %d\n",ans1-1,ans2-1); } else { int a,b; scanf("%d%d",&a,&b); a++,b++; if(a>b) swap(a,b); int ans=query(a,b,1,n,1); printf("%d\n",b-a+1-ans); update(-1,a,b,1,n,1); } } puts(""); } return 0; }