Submission #516138

#TimeUsernameProblemLanguageResultExecution timeMemory
516138mosiashvililukaHoliday (IOI14_holiday)C++14
100 / 100
573 ms23796 KiB
#include"holiday.h" //#include "grader.h" #include<bits/stdc++.h> using namespace std; long long a,b,c,d,e,i,j,ii,jj,zx,xc,f[300009],D,pas,jm,n,g[300009],LF[300009][3],RG[300009][3],RR,za,T[300009],l,r,z,zz,k,seg[300009],seg2[300009],K; map <int, int> M; map <int, int>::iterator IT; void upd(int q, int w, int rr){ q=za+q-1; while(q!=0){ seg[q]+=w;seg2[q]+=rr; q/=2; } } void wv(){ za=1; while(za<a) za*=2; for(i=0; i<=za*2; i++){ seg[i]=seg2[i]=0; } for(i=0; i<=za; i++) T[i]=0; M.clear(); for(i=1; i<=a; i++) M[f[i]]=1; zx=0; for(IT=M.begin(); IT!=M.end(); IT++){ zx++;M[(*IT).first]=zx;T[zx]=(*IT).first; } for(i=1; i<=a; i++) f[i]=M[f[i]]; // upd(f[1],1,T[f[1]]);K=1; } void Moveto(int q){ while(K<q){ K++;upd(f[K],1,T[f[K]]); } while(K>q){ upd(f[K],-1,-T[f[K]]);K--; } } void read(int q, int w, int rr){ if(q>w||k<=0) return; if(seg[rr]<=k){ k-=seg[rr]; z+=seg2[rr]; return; } if(q==w){ z+=T[q]*k; k=0; return; } read((q+w)/2+1,w,rr*2+1); read(q,(q+w)/2,rr*2); } void rec(int q, int w, int qq, int ww){ if(q>w) return; int mid=(q+w)/2,we=0; long long qw=0; for(int h=qq; h<=ww; h++){ Moveto(h); k=mid-(h-1)*RR;z=0; if(k<=0) break; read(1,za,1); if(qw<z){ qw=z;we=h; } } LF[mid][RR]=qw; rec(q,mid-1,qq,we); rec(mid+1,w,we,ww); } long long int findMaxAttraction(int Nn, int start, int Dd, int attraction[]) { n=Nn;start++;D=Dd;a=n; for(i=1; i<=n; i++){ g[i]=attraction[i-1];f[i]=g[i]; } for(i=start; i<=n; i++){ f[i-start+1]=g[i]; } a=n-start+1;RR=1; wv(); rec(1,D,1,a); RR=2; rec(1,D,1,a); for(i=1; i<=D; i++){ RG[i][1]=LF[i][1];RG[i][2]=LF[i][2]; LF[i][1]=LF[i][2]=0; } if(start!=1){ for(i=start-1; i>=1; i--){ f[start-1-i+1]=g[i]; } a=start-1;RR=1; wv(); rec(1,D,1,a); RR=2; rec(1,D,1,a); } // if(start==1) return RG[D][1]; pas=max(pas,RG[D][1]); for(i=0; i<=D; i++){ if(D-i-2>=0){ zx=LF[i][2]+RG[D-i-2][1]; pas=max(pas,zx); } if(D-i-1>=0){ zx=RG[i][2]+LF[D-i-1][1]; pas=max(pas,zx); } } return pas; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...