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 <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
int cnt = 1, cur = 0, jp[1000005][21], depth[1000005];
struct node {
char val;
int par;
} tree[1000005];
vector<int> pos;
void Init() { /* lol who inits amirite */ }
void TypeLetter(char L) {
tree[cnt] = { L, cur };
jp[cnt][0] = cur;
depth[cnt] = depth[cur] + 1;
cur = cnt;
for (int k = 1; k <= 20; k++) jp[cur][k] = jp[jp[cur][k-1]][k-1];
pos.push_back(cur);
cnt++;
}
void UndoCommands(int U) {
int nd = pos[pos.size() - 1 - U];
cur = nd;
pos.push_back(cur);
}
char GetLetter(int P) {
int x = depth[cur] - P - 1;
int c = cur;
for (int k = 20; k >= 0; k--) {
if ((x >> k) & 1) c = jp[c][k];
}
return tree[c].val;
}
# | 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... |