# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
419426 | Bill_00 | Crayfish scrivener (IOI12_scrivener) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
char last;
int a[1000005][25],cnt,lol[1000005],sz[1000005];
char x[1000005];
int find(int num){
return lol[num]=(lol[num]==num?num:find(lol[num]));
}
void TypeLetter(char L) {
cnt++;
x[cnt]=L;
sz[cnt]=sz[find(cnt-1)]+1;
lol[cnt]=cnt;
a[cnt][0]=find(cnt-1);
for(int i=1;i<=20;i++){
a[cnt][i]=a[a[cnt][i-1]][i-1];
}
}
void UndoCommands(int U) {
cnt++;
lol[cnt]=find(cnt-U-1);
sz[cnt]=sz[find(cnt-U-1)];
}
char GetLetter(int P) {
int siz=sz[find(cnt)];
int k=siz-P-1;
int y=find(cnt);
for(int i=20;i>=0;i--){
if(k>=(1<<i)){
y=a[y][i];
k-=(1<<i);
}
}
return x[y];
}