Submission #18807

#TimeUsernameProblemLanguageResultExecution timeMemory
18807ggohJousting tournament (IOI12_tournament)C++98
100 / 100
71 ms6472 KiB
#include<cstdio> #include<set> int maxx=-1,l,j,X,a,u,p,q,sz,seg[1<<18],w[100003],ss[100003],ee[100003],sum[100003],b,c,i,x[100002],st[100002],en[100002],d[100004]; bool check[100002]; int segloc(int num,int s,int e,int co) { if(s==e)return s; if(seg[num*2]<co)return segloc(num*2+1,(s+e)/2+1,e,co-seg[num*2]); else return segloc(num*2,s,(s+e)/2,co); } int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { a=N; b=C; X=1<<17; for(i=0;i<a;i++) { seg[X+i]=1; q=X+i;q/=2; while(q) { seg[q]=seg[2*q]+seg[2*q+1]; q/=2; } ee[i]=ss[i]=i; } for(i=0;i<b;i++) { u=segloc(1,0,X-1,S[i]+1); for(j=1;j<E[i]-S[i];j++) { p=segloc(1,0,X-1,S[i]+2); ss[p]=ee[p]=0; seg[X+p]=0; q=X+p;q/=2; while(q) { seg[q]=seg[2*q]+seg[2*q+1]; q/=2; } } p=segloc(1,0,X-1,S[i]+2); ee[u]=ee[p]; ss[p]=ee[p]=0; seg[X+p]=0; q=X+p;q/=2; while(q) { seg[q]=seg[2*q]+seg[2*q+1]; q/=2; } st[i]=ss[u];en[i]=ee[u]; } for(i=0;i<a-1;i++){if(K[i]>R)x[i]=1;else x[i]=0;} sum[0]=x[0]; for(i=1;i<a-1;i++)sum[i]=sum[i-1]+x[i]; for(i=0;i<b;i++) { if(sum[en[i]-1]-(st[i]?sum[st[i]-1]:0)==0)check[i]=1; else check[i]=0; } for(i=0;i<b;i++)if(check[i]) { d[st[i]]++; d[en[i]+1]--; } c=0; for(i=0;i<a;i++) { c+=d[i]; if(c>maxx)maxx=c,l=i; } return l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...