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)
using namespace std;
using i64 = long long;
int const MAXN=1<<20;
int n;
int a[MAXN];
int to[MAXN];
i64 solve(int l,int r) {
if (r-l<=1) return 0;
int m=(l+r)/2;
i64 res=solve(l,m)+solve(m+1,r);
int i=m,j=m+1;
int lo=to[a[i]];
int hi=to[a[j]];
if (lo>hi) swap(lo,hi);
while (l>=lo && hi<=r) {
if (lo<i) {
i-=1;
lo=min(lo,to[a[i]]);
hi=max(hi,to[a[i]]);
} else if (j<hi) {
j+=1;
lo=min(lo,to[a[j]]);
hi=max(hi,to[a[j]]);
} else {
break;
}
}
if (i==lo && j==hi) res+=1;
return res;
}
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];
i64 N=1<<n;
rep(i,0,1<<n) to[N-1-a[i]]=i;
cout<<N*(N+1)/2-solve(0,(1<<n)-1)<<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... |