NOI2017整数

整数

全WA啊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+1,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==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+1,int o=1)
 42 {
 43     if(l==r) return sum[pos];
 44     pushdown(l,r,o);
 45     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+1,int o=1)
 52 {
 53     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 
 71 IL int judge(int f,int x,int y,int l=1,int r=n+1,int o=1)
 72 {
 73     if(x<=l&&r<=y) return tree[f][o];
 74     int ans=1;
 75     pushdown(l,r,o);
 76     if(x<=mid) ans=ans&&judge(f,x,y,l,mid,lson);
 77     if(mid<y) ans=ans&&judge(f,x,y,mid+1,r,rson);
 78     pushup(o);
 79     return ans;
 80 }
 81 IL void setit(int f,int x,int y,int l=1,int r=n+1,int o=1)
 82 {
 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 
 97 IL int search(int f,int l,int r=n+1)
 98 {
 99     while(l<r) 
100     if(judge(f,l,mid)) l=mid+1;
101     else r=mid;
102     return l;
103 }
104 
105 int main()
106 {
107     //freopen("int.in","r",stdin);
108     memset(mark,0xff,sizeof(mark));
109     n=read(),t1=read(),t2=read(),t3=read();
110     build();
111     for(RG int i=1;i<=n;++i)
112     {
113         RG int ope=read();
114         if(ope==1)
115         {
116             int a=read(),b=read(),flag=1;
117             if(a<0) flag=-1,a=-a;
118             for(RG int j=0;a>>j;++j)
119             {
120                 if(!(a&(1<<j))) continue; 
121                 int f=flag;
122                 RG int pos=(j+b)/30+1;
123                 RG int v=1<<((j+b)%30);
124                 if((f=add(f,pos,v))!=0) {
125                     int endpos=search(f==1,pos+1);
126                     add(f,endpos,1);
127                     if(endpos-1>=pos+1) setit(f==-1,pos+1,endpos-1);
128                 }
129             }
130         }
131         else{
132             RG int k=read();
133             RG int ans=(query(k/30+1)>>(k%30))&1;
134             printf("%d\n",ans);
135         }
136     }
137     return 0;
138 }

猜你喜欢

转载自www.cnblogs.com/MediocreKonjac/p/9167574.html