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 Nmax = 1e6 + 5, lg = 20;
int nodes, t[lg+2][Nmax], p[lg+2][Nmax], up[Nmax];
char letter[Nmax];
void Init()
{
}
void TypeLetter(char L)
{
letter[++nodes] = L;
t[0][nodes] = nodes - 1;
p[0][nodes] = nodes - 1;
up[nodes] = up[nodes - 1] + 1;
int i;
for(i=1; i<=lg; ++i)
t[i][nodes] = t[i-1][t[i-1][nodes]],
p[i][nodes] = p[i-1][p[i-1][nodes]];
}
void UndoCommands(int U)
{
p[0][nodes + 1] = nodes;
int cursor = nodes, i;
for(i=0; i<=lg; ++i)
if(U & (1<<i)) cursor = p[i][cursor];
t[0][nodes + 1] = cursor;
up[++nodes] = up[cursor];
for(i=1; i<=lg; ++i)
t[i][nodes] = t[i-1][t[i-1][nodes]],
p[i][nodes] = p[i-1][p[i-1][nodes]];
}
char GetLetter(int P)
{
int i, x = nodes; ++P;
for(i=lg; i>=0; --i)
if(up[t[i][x]] >= P) x = t[i][x];
return letter[x];
}
# | 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... |