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;
int t[N][26], p[N][21], idx, d[N];
int tym, node[N], lsb[N], lg[N];
char c[N];
void Init() {
lg[1] = 0;
for(int i = 2; i < N; i++)
lg[i] = lg[i >> 1] + 1;
for(int i = 1; i < N; i++)
lsb[i] = lg[i & -i];
}
void TypeLetter(char L) {
int u = node[tym];
int &v = t[u][L - 'a'];
if(!v) {
v = ++idx;
p[v][0] = u;
for(int i = 1; i <= 20 && p[v][i - 1]; i++)
p[v][i] = p[p[v][i - 1]][i - 1];
} c[v] = L;
node[++tym] = v;
d[v] = d[u] + 1;
}
void UndoCommands(int U) {
int u = node[tym - U];
node[++tym] = u;
}
char GetLetter(int P) {
int u = node[tym];
int k = d[u] - P - 1;
while(k) {
u = p[u][lsb[k]];
k ^= k & -k;
} return c[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... |