This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3dSgv16 ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
signed main(){
_3dSgv16;
int ln;
cin>>ln;
const int n=1<<ln;
vi a(n);
rep(i,n){
cin>>a[i];
}
vi ps;
rep(i,n){
ps.pb((!sz(ps)?0:ps.back())^a[i]);
}
vi ids(n);
rep(i,n){
ids[a[i]]=i;
}
vi rbe(n);
rep(i,n){
rbe[i]=ids[(n-1)^a[i]];
}
int ans=n*(n+1)/2;
rep(i,n){
per(j,i){
if((i-j+1)%4==0 and ps[i]==(!j?0:ps[j-1])){
bool pok=1;
for(int k=j;k<=i;k++){
pok=pok and (rbe[k]>=j and rbe[k]<=i);
}
ans-=pok;
}
}
}
print(ans);
// const int m=4;
// rep(d,m){
// map<int,vi> mp;
// for(int i=d;i<n;i+=m){
// int now=ps[i];
// if(sz(mp)){
// int l=0,r=sz(mp[now])-1;
// int c=-1;
// while(l<=r){
// int m=(l+r)/2;
// bool pok=1;
// {
// for(int j=mp[now][m];j<=i;j++){
// if(rbe[j]<mp[now][m] or rbe[j]>i){
// pok=0;
// }
// }
// }
// if(pok){
// c=m,l=m+1;
// }else{
// r=m-1;
// }
// }
// if(c!=-1 and c+1<sz(mp[now])){
// ans-=(i-mp[now][c+1])/4;
// }
// }
// mp[now].pb(i);
// }
// }
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |