Submission #12698

#TimeUsernameProblemLanguageResultExecution timeMemory
12698dohyun0324Holiday (IOI14_holiday)C++98
0 / 100
0 ms65536 KiB
#include"holiday.h" #include<string.h> #include<algorithm> using namespace std; int s,t=1,pos[100010],k,e[21],p2[300010]; long long dap,r1[300010],l1[300010],r2[300010],l2[300010],p[300010]; struct data{ int x,y; bool operator<(const data&r)const{ return x>r.x; } }a[100010]; struct data2{ int num; long long sum; }tree[21][300010]; void update(int lev,int x){ int p=x+t-1; while(p>0){ tree[lev][p].num++; tree[lev][p].sum+=a[x].x; p/=2; } } void finding(int lev,int x,int y,int k,int num){ if(x==y){s=x-1; return;} if(num-tree[lev][k*2].num>=0) { finding(lev,(x+y)/2+1,y,k*2+1,num-tree[lev][k*2].num); } else finding(lev,x,(x+y)/2,k*2,num); } long long query(int lev,int x,int y,int k,int s,int e){ if(s<=x && y<=e) return tree[lev][k].sum; if(s>y || e<x) return 0; return query(lev,x,(x+y)/2,k*2,s,e)+query(lev,(x+y)/2+1,y,k*2+1,s,e); } void gap(int m,int x,int y,int lev,int sw){ int i,ps=0; long long maxi=0; for(i=e[lev]+1;i<x;i++) update(lev,pos[i]); for(i=x;i<=y;i++) { if(tree[lev][pos[i]+t-1].num==0) update(lev,pos[i]); if(sw==1) finding(lev,1,t,1,m-(i-1)); else finding(lev,1,t,1,m-(i-1)*2); if(maxi<query(lev,1,t,1,1,s)) { maxi=query(lev,1,t,1,1,s); ps=i; } } e[lev]=y; p[m]=maxi; p2[m]=ps; } void pro(int m1,int m2,int x,int y,int lev,int sw){ int m=(m1+m2)/2; gap(m,x,y,lev,sw); if(m1==m2 || p2[m]==0) return; pro(m1,(m1+m2)/2,x,p2[m],lev+1,sw); pro((m1+m2)/2+1,m2,p2[m],y,lev+1,sw); } void init(){ int i; for(i=0;i<=20;i++) e[i]=1; memset(tree,0,sizeof tree); } long long int findMaxAttraction(int n, int start, int d, int attraction[]) { int i; for(i=start;i>=0;i--) a[start-i+1].x=attraction[i], a[start-i+1].y=start-i+1; for(i=1;;i++){if(t>=start+1) break; t*=2;} sort(a+1,a+start+2); for(i=1;i<=(start+1);i++) pos[a[i].y]=i; init(); pro(1,start*3,2,start+1,0,1); for(i=1;i<=start*3;i++) l1[i]=p[i]; init(); pro(1,start*3,2,start+1,0,2); for(i=1;i<=start*3;i++) l2[i]=p[i]; for(i=start;i<n;i++) a[i-start+1].x=attraction[i], a[i-start+1].y=i-start+1; t=1; for(i=1;;i++){if(t>=n-start) break; t*=2;} sort(a+1,a+n-start+1); for(i=1;i<=n-start;i++) pos[a[i].y]=i; init(); pro(1,(n-start-1)*3,2,n-start,0,1); for(i=1;i<=(n-start-1)*3;i++) r1[i]=p[i]; init(); pro(1,start*3,2,start+1,0,2); for(i=1;i<=(n-start-1)*3;i++) r2[i]=p[i]; for(i=0;i<=d;i++){ if(dap<l1[i]+r2[d-i]) dap=l1[i]+r2[d-i]; if(dap<l2[i]+r1[d-i]) dap=l2[i]+r1[d-i]; if(i>=1 && dap<l1[i-1]+r2[d-i]+attraction[start]) dap=l1[i-1]+r2[d-i]+attraction[start]; if(i>=1 && dap<l2[i-1]+r1[d-i]+attraction[start]) dap=l2[i-1]+r1[d-i]+attraction[start]; } return dap; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...