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>
int p[1000005][22];
char character[1000005];
int point[1000005];
int depth[1000005];
int x = 0;
int cur = 0;
int mcur = 0;
void Init() {
for(int i = 0;i < 22;i++)
p[0][i] = -1;
depth[0] = 0;
}
void TypeLetter(char L) {
int next = mcur + 1;
point[x] = next;
character[next] = L;
depth[next] = depth[cur] + 1;
p[next][0] = cur;
for(int i = 1;i < 22;i++){
if(p[next][i-1] != -1) p[next][i] = p[p[next][i-1]][i-1];
else {p[next][i] = -1; continue;}
}
cur = next;
mcur++;
x++;
}
void UndoCommands(int U) {
cur = point[x - U - 1];
point[x] = cur;
x++;
}
char GetLetter(int P) {
int k = depth[cur] - P - 1;
int node = cur;
while(k > 0){
int kk = (k & (-k));
k -= kk;
kk = log2(kk);
node = p[node][kk];
}
return character[node];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |