# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
485283 |
2021-11-07T01:32:15 Z |
errorgorn |
Dojave (COCI17_dojave) |
C++17 |
|
1135 ms |
163288 KB |
//雪花飄飄北風嘯嘯
//天地一片蒼茫
#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());
const int INF=1e9;
struct node{
int s,e,m;
ii val;
ll lazy=0;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
val=ii(-1,s);
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void propo(){
if (lazy){
val.fi+=lazy;
if (s!=e){
l->lazy+=lazy;
r->lazy+=lazy;
}
lazy=0;
}
}
void update(int i,int j,ll k){
if (s==i && e==j){
lazy+=k;
}
else{
if (j<=m) l->update(i,j,k);
else if (m<i) r->update(i,j,k);
else l->update(i,m,k),r->update(m+1,j,k);
l->propo(),r->propo();
val=max(l->val,r->val);
}
}
} *root=new node(0,1100005);
int n;
int arr[1100000];
int temp[1100000];
ii cnt[1100000];
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;
ll ans=(1LL<<n)*((1LL<<n)+1)/2;
memset(temp,-1,sizeof(temp));
rep(x,0,1<<n){
if (temp[arr[x]]==-1) temp[af^arr[x]]=x;
}
rep(x,0,1<<n){
if (x%4<2) cnt[x].fi++;
else cnt[x].se++;
}
rep(x,0,1<<n){
if (x) root->update(0,x-1,-1);
if (temp[arr[x]]==-1){
root->update(0,x,-INF);
}
else{
root->update(0,temp[arr[x]],INF+2);
}
auto it=root->val;
if (it.fi==0){
cnt[x+1]=cnt[it.se];
if ((x+1)%4<2){
ans-=cnt[x+1].fi;
cnt[x+1].fi++;
}
else{
ans-=cnt[x+1].se;
cnt[x+1].se++;
}
//cout<<x+1<<" "<<cnt[x+1].fi<<" "<<cnt[x+1].se<<endl;
}
}
cout<<ans<<endl;
}
Compilation message
dojave.cpp: In constructor 'node::node(int, int)':
dojave.cpp:46:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | s=_s,e=_e,m=s+e>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
138072 KB |
Output is correct |
2 |
Correct |
93 ms |
142280 KB |
Output is correct |
3 |
Correct |
91 ms |
138076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
142276 KB |
Output is correct |
2 |
Correct |
95 ms |
142340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
142376 KB |
Output is correct |
2 |
Correct |
105 ms |
142452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
142508 KB |
Output is correct |
2 |
Correct |
106 ms |
142448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
142628 KB |
Output is correct |
2 |
Correct |
100 ms |
142660 KB |
Output is correct |
3 |
Correct |
99 ms |
142664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
143556 KB |
Output is correct |
2 |
Correct |
129 ms |
143784 KB |
Output is correct |
3 |
Correct |
151 ms |
145272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
143680 KB |
Output is correct |
2 |
Correct |
160 ms |
144928 KB |
Output is correct |
3 |
Correct |
219 ms |
148036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
288 ms |
147396 KB |
Output is correct |
2 |
Correct |
224 ms |
147396 KB |
Output is correct |
3 |
Correct |
220 ms |
147916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1135 ms |
162884 KB |
Output is correct |
2 |
Correct |
805 ms |
163012 KB |
Output is correct |
3 |
Correct |
605 ms |
162904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1129 ms |
162912 KB |
Output is correct |
2 |
Correct |
637 ms |
162884 KB |
Output is correct |
3 |
Correct |
583 ms |
163268 KB |
Output is correct |
4 |
Correct |
877 ms |
163288 KB |
Output is correct |