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;
const int N = 1e6+10;
char c[N];
int lev[N];
int cur, freePtr;
int p[20][N], state[N], ptr;
void Init() {
lev[0] = -1;
memset(p,-1,sizeof p);
c[0] = '?';
cur = 0; freePtr = 1;
state[0] = cur; ptr = 0;
}
void TypeLetter(char L) {
int idx = freePtr++;
p[0][idx] = cur;
c[idx] = L, lev[idx] = lev[cur] + 1;
cur = idx;
for(int j = 1; j < 20; ++j)
if(p[j-1][cur] + 1)
p[j][cur] = p[j-1][p[j-1][cur]];
state[++ptr] = cur;
}
void UndoCommands(int U) {
state[ptr+1] = state[max(0, ptr - U)];
ptr++;
cur = state[ptr];
}
char GetLetter(int P) {
int tmp = cur, need = lev[cur] - P;
for(int j = 19; j >= 0; --j)
if(need >= (1<<j)) {
need -= (1<<j);
tmp = p[j][tmp];
}
return c[tmp];
}
# | 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... |