agc043b
思路:
由于\(|1-3|=2\),操作一次后所有数都为012、
先不考虑2,那么操作过程可以看做异或
手模一下:
\[a_1,a_2,a_3,a_4
\]
\[a_1a_2,a_2a_3,a_3a_4
\]
\[a_1a_2^2a_3,a_2a_3^2a_4
\]
\[a_1a_2^3a_3^3a_4
\]
发现是二项式系数。可以直接做
但问题是还有2
但我们发现只要存在一个1,2就会在某个时刻和1挨在一起,答案就不可能是2
所以这种情况时2可以直接看做0
另一种就是只有02,那么将2看做1,最后将答案*2就可以了
这道题是经典的3转2的思路。
#include<bits/stdc++.h>
using namespace std;
struct FIO{static const int BUF_SIZE=1<<19;char _i[BUF_SIZE],*_1=_i,*_2=_i,_o[BUF_SIZE],*_t=_o;inline char _gt(){if(_1==_2){_1=_i;_2=_i+fread(_i,1,BUF_SIZE,stdin);}return _1==_2?EOF:*_1++;}inline void _pt(char c){if(_t-_o==BUF_SIZE){fwrite(_o,1,BUF_SIZE,stdout);_t=_o;}*_t++=c;}int _pr=6,le,_ob[20];template<typename T>FIO&operator>>(T&x){x=0;char c=_gt();bool sg=false;while(c!=EOF&&(c<'0'||c>'9')){if(c=='-')sg=true;c=_gt();}while(c!=EOF&&c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=_gt();}if(sg)x=-x;return*this;}FIO&operator>>(char*s){char c=_gt();while(c!=EOF&&c<33)c=_gt();while(c!=EOF&&c>=33)*s++=c,c=_gt();*s='\0';return*this;}FIO&operator>>(string&s){s.clear();char c=_gt();while(c!=EOF&&c<33)c=_gt();while(c!=EOF&&c>=33)s+=c,c=_gt();return*this;}FIO&operator>>(char&x){char c=_gt();while(c!=EOF&&c<33)c=_gt();x=c;return*this;}FIO&operator>>(double&x){x=0;char c=_gt();bool sg=0;while(c!=EOF&&c<33)c=_gt();if(c=='-'){sg=1;c=_gt();}while(c!=EOF&&c>='0'&&c<='9'){x=x*10+(c^48);c=_gt();}if(c=='.'){c=_gt();double tp=0.1;while(c!=EOF&&c>='0'&&c<='9'){x+=(c^48)*tp;tp*=0.1;c=_gt();}}if(sg)x=-x;return*this;}FIO&setprecision(int n){_pr=n<0?0:n;return*this;}template<typename T>FIO&operator<<(T x){if(x<0){_pt('-');x=-x;}if(x==0){_pt('0');return*this;}char _b[20];int ps=0;while(x>0){_b[ps++]=(x%10)^48;x/=10;}while(ps>0)_pt(_b[--ps]);return*this;}FIO&operator<<(const char*s){while(*s)_pt(*s++);return*this;}FIO&operator<<(const string&s){for(char c:s)_pt(c);return*this;}FIO&operator<<(char c){_pt(c);return*this;}FIO&operator<<(double x){if(x<0)_pt('-'),x=-x;if(isnan(x))return _pt('n'),_pt('a'),_pt('n'),*this;if(isinf(x))return _pt('i'),_pt('n'),_pt('f'),*this;long long ip=(long long)x;x-=ip;if(_pr==0){x*=10;if(x>=5)ip++;return*this<<ip;}le=0;_ob[0]=0;for(int i=1;i<=_pr;i++){x*=10;_ob[++le]=(int)x;x-=(int)x;}x*=10;int _tp=(int)x;if(_tp>=5){int j=le;_ob[le]++;while(_ob[j]==10)_ob[j-1]++,_ob[j]=0,j--;}ip+=_ob[0];*this<<ip<<".";for(int i=1;i<=le;i++)*this<<_ob[i];return*this;}~FIO(){fwrite(_o,1,_t-_o,stdout);}}fst;
#define cin fst
#define cout fst
#define il inline
#define N 1000005
#define int long long
int n,a[N];
typedef long long ll;
#define mod 2
signed main(){
cin>>n; bool f1=0;
for(int i=1;i<=n;i++){
char ch; cin>>ch;
a[i]=(ch-'0');
}
for(int i=1;i<n;i++){
a[i]=abs(a[i]-a[i+1]);
f1|=(a[i]==1);
}
n--;
int mul=1;
if(!f1){
mul=2;
for(int i=1;i<=n;i++)a[i]>>=1;
}
for(int i=1;i<=n;i++)a[i]=a[i]%mod;
ll res=0;
for(int i=1;i<=n;i++){
if(!a[i])continue;
res^=(((n-1)&(i-1))==i-1);
}
cout<<res*mul;
return 0;
}

浙公网安备 33010602011771号