TLE QAQ
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define N 1000010 4 #define INF (1<<30) 5 #define RG register 6 #define IL inline 7 #define lson (o<<1) 8 #define rson (o<<1|1) 9 #define mid ((l+r)>>1) 10 IL bool isitdigit(char c){ return c<='9'&&c>='0'; } 11 IL int read() 12 { 13 RG int s,f=1;RG char c; 14 while (!isitdigit(c=getchar())) (c=='-')&&(f=-1); 15 for(s=c-'0';isitdigit(c=getchar());s=(s<<1)+(s<<3)+c-'0'); 16 return s*f; 17 } 18 int n,t1,t2,t3; 19 int tree[2][4*N],mark[4*N],sum[N]; 20 IL void build(int l=1,int r=N,int o=1) 21 { 22 tree[0][o]=1; 23 if(l==r) return ; 24 build(l,mid,lson);build(mid+1,r,rson); 25 } 26 IL void pushdown(int l,int r,int o) 27 { 28 if(!(~mark[o])) return; 29 mark[lson]=mark[rson]=mark[o]; 30 tree[0][lson]=tree[0][rson]=!mark[o]; 31 tree[1][lson]=tree[1][rson]=mark[o]; 32 if(mid==l) sum[l]=mark[o]*(INF-1); 33 if(mid+1==r) sum[r]=mark[o]*(INF-1); 34 mark[o]=-1; 35 } 36 IL void pushup(int o) 37 { 38 tree[0][o]=tree[0][lson]&&tree[0][rson]; 39 tree[1][o]=tree[1][lson]&&tree[1][rson]; 40 } 41 IL int query(int pos,int l=1,int r=N,int o=1) 42 { 43 if(l==r) return sum[pos]; 44 pushdown(l,r,o); 45 RG int res; 46 if(pos<=mid) res= query(pos,l,mid,lson); 47 else res=query(pos,mid+1,r,rson); 48 pushup(o); 49 return res; 50 } 51 IL int add(int f,int pos,int v,int l=1,int r=N,int o=1) 52 { 53 RG int res; 54 if(l==r) 55 { 56 sum[pos]+=f*v; 57 if(f==-1) res=sum[pos]<0; 58 else res=sum[pos]>INF-1; 59 sum[pos]-=f*INF*res; 60 tree[1][o]=sum[pos]==INF-1; 61 tree[0][o]=sum[pos]==0; 62 return res*f; 63 } 64 pushdown(l,r,o); 65 if(pos<=mid) res=add(f,pos,v,l,mid,lson); 66 else res=add(f,pos,v,mid+1,r,rson); 67 pushup(o); 68 return res; 69 } 70 IL int judge(int f,int x,int y,int l=1,int r=N,int o=1) 71 { 72 if(x<=l&&r<=y) return tree[f][o]; 73 RG int ans=1; 74 pushdown(l,r,o); 75 if(x<=mid) ans=ans&&judge(f,x,y,l,mid,lson); 76 if(mid<y) ans=ans&&judge(f,x,y,mid+1,r,rson); 77 pushup(o); 78 return ans; 79 } 80 IL void setit(int f,int x,int y,int l=1,int r=N,int o=1) 81 { 82 //if(3<=l&&4>=r) debug=-1; 83 if(x<=l&&r<=y) 84 { 85 if(l==r) sum[l]=f*(INF-1); 86 mark[o]=f; 87 tree[0][o]=!mark[o]; 88 tree[1][o]=mark[o]; 89 return ; 90 } 91 pushdown(l,r,o); 92 if(x<=mid) setit(f,x,y,l,mid,lson); 93 if(mid<y) setit(f,x,y,mid+1,r,rson); 94 pushup(o); 95 } 96 IL int search(int f,int l,int r=N) 97 { 98 while(l<r) 99 if(judge(f,l,mid)) l=mid+1; 100 else r=mid; 101 return l; 102 } 103 int main() 104 { 105 memset(mark,0xff,sizeof(mark)); 106 n=read(),t1=read(),t2=read(),t3=read(); 107 build(); 108 for(RG int i=1;i<=n;++i) 109 { 110 RG int ope=read(); 111 if(ope==1) 112 { 113 RG int a=read(),b=read(),flag=1; 114 if(a<0) flag=-1,a=-a; 115 for(RG int j=0;a>>j;++j) 116 { 117 if(!(a&(1<<j))) continue; 118 RG int f=flag; 119 RG int pos=(j+b)/30+1; 120 RG int v=1<<((j+b)%30); 121 if((f=add(f,pos,v))!=0) { 122 RG int endpos=search(f==1,pos+1); 123 add(f,endpos,1); 124 if(endpos-1>=pos+1) setit(f==-1,pos+1,endpos-1); 125 } 126 } 127 } 128 else{ 129 RG int k=read(); 130 RG int ans=(query(k/30+1)>>(k%30))&1; 131 printf("%d\n",ans); 132 } 133 } 134 return 0; 135 }