Submission #56252

#TimeUsernameProblemLanguageResultExecution timeMemory
56252hamzqq9Dojave (COCI17_dojave)C++14
140 / 140
3349 ms83944 KiB
#include<bits/stdc++.h> #define lf double #define ll long long #define ull unsigned ll #define ii pair<int,int> #define li pair<ll,int> #define iii pair<ii,int> #define iiii pair<ii,ii> #define iiii2 pair<int,iii> #define lii pair<ll,ii> #define lolo pair<ll,ll> #define heap priority_queue #define mp make_pair #define st first #define nd second #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define all(x) x.begin(),x.end() #define len(x) strlen(x) #define sz(x) (int) x.size() #define orta ((bas+son)/2) #define min3(x,y,z) min(min(x,y),z) #define max3(x,y,z) max(max(x,y),z) #define umin(x,y) x=min(x,y) #define umax(x,y) x=max(x,y) #define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" " #define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar() #define MOD 1000000007 #define inf 1000000001 #define N pw(21)+3 #define LOG 20 #define magic 100 #define MAX 1000005 #define KOK 350 #define EPS 0.000000000001 #define pw(x) (1<<(x)) #define PI 3.1415926535 using namespace std; struct SEG { int mn[4],cnt[4]; } S[N*4]; int n,x; int lazy[N*4],pos[N],match[N]; bool ok[N]; ll NO; void push(int node,int bas,int son) { for(int i=0;i<4;i++) { S[node*2].mn[i]+=lazy[node]; S[node*2+1].mn[i]+=lazy[node]; } lazy[node*2]+=lazy[node]; lazy[node*2+1]+=lazy[node]; lazy[node]=0; } SEG merge(SEG A,SEG B) { SEG result; for(int i=0;i<4;i++) { result.cnt[i]=0; result.mn[i]=min(A.mn[i],B.mn[i]); if(A.mn[i]==result.mn[i]) result.cnt[i]+=A.cnt[i]; if(B.mn[i]==result.mn[i]) result.cnt[i]+=B.cnt[i]; } return result; } SEG get(int node,int bas,int son,int x,int y) { if(bas>=x && son<=y) return S[node]; push(node,bas,son); if(orta>=x) { if(orta+1<=y) { return merge(get(node*2,bas,orta,x,y),get(node*2+1,orta+1,son,x,y)); } else return get(node*2,bas,orta,x,y); } else return get(node*2+1,orta+1,son,x,y); } void up(int node,int bas,int son,int x,int y,int val) { if(bas>y || son<x) return ; if(bas>=x && son<=y) { for(int i=0;i<4;i++) S[node].mn[i]+=val; lazy[node]+=val; return ; } push(node,bas,son); up(node*2,bas,orta,x,y,val); up(node*2+1,orta+1,son,x,y,val); S[node]=merge(S[node*2],S[node*2+1]); } void build(int node,int bas,int son) { if(bas==son) { for(int i=0;i<4;i++) S[node].cnt[i]=0,S[node].mn[i]=1; S[node].mn[bas%4]=0; S[node].cnt[bas%4]=1; return ; } build(node*2,bas,orta); build(node*2+1,orta+1,son); S[node]=merge(S[node*2],S[node*2+1]); } int main() { #if 0 freopen("input.txt","r",stdin); #endif scanf("%d",&n); n=pw(n); for(int i=1;i<=n;i++) { scanf("%d",&x); pos[x]=i; } for(int i=0;i<n;i++) { match[pos[i]]=pos[n-1-i]; } build(1,1,n); for(int i=1;i<=n;i++) { if(!ok[match[i]]) { up(1,1,n,1,i,1); } else { up(1,1,n,1,match[i],-1); up(1,1,n,match[i]+1,i,1); } SEG RES=get(1,1,n,1,i); if(RES.mn[(i+1)%4]==0) NO+=RES.cnt[(i+1)%4]; ok[i]=1; } printf("%lld",1ll*n*(n+1)/2-NO-(n==2)); }

Compilation message (stderr)

dojave.cpp: In function 'int main()':
dojave.cpp:159:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
dojave.cpp:165:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
   ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...