This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//雪花飄飄北風嘯嘯
//天地一片蒼茫
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n;
int arr[1100000];
bool cnt[1100000];
bool f[1100000];
vector<int> v;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n;
rep(x,0,1<<n) cin>>arr[x];
if (n==1){
cout<<2<<endl;
return 0;
}
int af=(1<<n)-1;
rep(x,0,1<<n){
if (!cnt[arr[x]]){
f[x]=true;
cnt[af^arr[x]]=true;
}
}
ll r0=1,r1=1,r2=0,r3=0;
int num=0;
rep(x,1,(1<<n)+1){
if (f[x-1]) num++;
if (x%2==0 && x/2==num){
if (x%4==0) r0++;
else r2++;
}
}
rep(x,0,1<<n) if ((arr[x]^af)==arr[0]) f[x]=1;
num=0;
rep(x,1,(1<<n)){
if (f[x]) num++;
if (x%2==0 && x/2==num){
if (x%4==0) r1++;
else r3++;
}
}
ll ans=(1LL<<n)*((1LL<<n)+1);
ans-=r0*(r0-1);
ans-=r1*(r1-1);
ans-=r2*(r2-1);
ans-=r3*(r3-1);
cout<<(ans)/2;
}
# | 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... |