P3822 [NOI2017]整数
shadowice大佬已经写的非常详细了我就不再写一遍了……
//minamoto
#include<bits/stdc++.h>
#define u unsigned int
#define fp(i,a,b) for(register int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(register int i=a,I=b-1;i>I;--i)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
int res,f=1;char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
const int N=1e6+5;
u inc[N],ded[N],st,add,las,v1,v2;int n,x,p,q,a,b,ans;set<int>s;set<int>::iterator it;
int main(){
// freopen("testdata.in","r",stdin);
n=read(),read(),read(),read();
while(n--){
x=read();
if(x==1){
a=read(),b=read(),p=b/32,q=b%32;
if(a>0){
st=(u)a<<q,add=(u)a>>(31-q),add>>=1;
las=inc[p],inc[p]+=st;add+=(las>inc[p]);
if(inc[p]!=ded[p])s.insert(p);else if(s.count(p))s.erase(p);
while(add){
++p,las=inc[p],inc[p]+=add,add=(las>inc[p]);
if(inc[p]!=ded[p])s.insert(p);else if(s.count(p))s.erase(p);
}
}else{
a=-a,st=(u)a<<q,add=(u)a>>(31-q),add>>=1;
las=ded[p],ded[p]+=st;add+=(las>ded[p]);
if(inc[p]!=ded[p])s.insert(p);else if(s.count(p))s.erase(p);
while(add){
++p,las=ded[p],ded[p]+=add,add=(las>ded[p]);
if(inc[p]!=ded[p])s.insert(p);else if(s.count(p))s.erase(p);
}
}
}else{
b=read();p=b/32,q=b%32,ans=((inc[p]>>q)^(ded[p]>>q))&1;
v1=inc[p]%(1<<q),v2=ded[p]%(1<<q);
if(v1<v2)ans^=1;
else if(v1==v2&&!s.empty()&&p>(*s.begin())){
it=s.lower_bound(p);--it;
if(inc[*it]<ded[*it])ans^=1;
}puts(ans?"1":"0");
}
}return 0;
}
深深地明白自己的弱小