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>
#define sz(c) int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
#define bin(x) bitset<4>(x)
using namespace std;
using i64 = long long;
int const MAXN=1<<21;
int n;
int a[MAXN];
int p[MAXN];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cout<<fixed<<setprecision(10);
cin>>n;
rep(i,0,1<<n) cin>>a[i];
if (n==1) {
cout<<2<<endl;
return 0;
}
int N=1<<n;
rep(i,0,1<<n) p[N-1-a[i]]=i;
i64 res=i64(N+1)*N/2;
rep(i,0,N) {
rep(j,i+1,N) {
if (p[a[j]]<i) break;
if ((j-i+1)%4==0) {
bool ok=true;
rep(k,i,j+1) if (p[a[k]]<i || p[a[k]]>j) {
ok=false;
j=max(j,p[a[k]]-1);
break;
}
if (ok) { res-=1; }
}
}
}
cout<<res<<endl;
return 0;
}
# | 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... |