Submission #117198

#TimeUsernameProblemLanguageResultExecution timeMemory
117198imyujinTreasure Hunt (CEOI11_tre)C++14
100 / 100
2848 ms97400 KiB
#include<stdio.h> #define MAXN 400010 int n; int num[MAXN], dep[MAXN], pidx[MAXN][20], pnum[MAXN][20], pdep[MAXN][20]; int bsnum(int x){ int s=0, e=n-1; while(s<e){ int m=(s+e)/2; if(x<=num[m]) e=m; else s=m+1; } return s; } int bsdep(int d, int idx){ for(int i=19; i>=0; i--) if(pdep[idx][i]>=d) idx=pidx[idx][i]; return idx; } void init(){ n=1; num[0]=1; dep[0]=0; for(int i=0; i<20; i++){ pidx[0][i]=pdep[0][i]=0; pnum[0][i]=1; } } void path(int a, int s){ num[n]=num[n-1]+s; pidx[n][0]=bsnum(a); pdep[n][0]=dep[pidx[n][0]]-num[pidx[n][0]]+a; pnum[n][0]=a; dep[n]=pdep[n][0]+s; for(int i=1; i<20; i++){ pidx[n][i]=pidx[pidx[n][i-1]][i-1]; pdep[n][i]=pdep[pidx[n][i-1]][i-1]; pnum[n][i]=pnum[pidx[n][i-1]][i-1]; } n++; } int dig(int a, int b){ int aidx, bidx, adep, bdep, atidx, btidx; aidx=bsnum(a), bidx=bsnum(b); adep=dep[aidx]-num[aidx]+a, bdep=dep[bidx]-num[bidx]+b; int s=0, e=adep<bdep?adep:bdep; while(s<e){ int m=(s+e+1)/2; atidx=bsdep(m, aidx); btidx=bsdep(m, bidx); if(atidx==btidx) s=m; else e=m-1; } //printf("{%d %d}\n", bsdep(1, aidx), bsdep(1, bidx)); //printf("[%d]\n", s); int d, idx; if(adep<bdep){ d=s+(bdep-adep)/2; idx=bsdep(d, bidx); } else{ d=s+(adep-bdep+1)/2; idx=bsdep(d, aidx); } return num[idx]-dep[idx]+d; }
#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...