This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define N 1000001
#define LN 19 /* LN = floor(log2(N)) */
int uu[N], pp[N][LN + 1], dd[N], n_, i; char cc[N];
void Init() {
n_ = 1;
}
void TypeLetter(char c) {
int l, u;
i++;
u = uu[i] = n_++;
cc[u] = c, pp[u][0] = uu[i - 1], dd[u] = dd[uu[i - 1]] + 1;
for (l = 1; 1 << l <= dd[u]; l++)
pp[u][l] = pp[pp[u][l - 1]][l - 1];
}
void UndoCommands(int k) {
i++, uu[i] = uu[i - 1 - k];
}
char GetLetter(int d) {
int u = uu[i], l;
d++;
for (l = LN; l >= 0; l--)
if (dd[u] - d >= 1 << l)
u = pp[u][l];
return cc[u];
}
# | 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... |