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 <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define ad push_back
using namespace std;
const int N = 1e6 + 1;
int a[N], i1 = 1, nax[N];
int p[N][18];
char c[N];
void Init()
{
}
void TypeLetter(char L)
{
a[i1] = a[i1 - 1] + 1;
nax[i1] = nax[i1 - 1];
c[i1++] = L;
}
void UndoCommands(int U)
{
a[i1] = a[i1 - U - 1];
nax[i1] = i1;
p[i1][0] = nax[i1 - U - 1];
for (int i = 1; i < 18; i++) p[i1][i] = p[p[i1][i - 1]][i - 1];
i1++;
}
char GetLetter(int P)
{
P++;
int s = nax[i1 - 1];
if (a[s] < P) return c[s + P - a[s]];
for (int i = 17; i >= 0; i--) if (a[p[s][i]] >= P)s = p[s][i];
s = p[s][0];
return c[s + P - a[s]];
}
# | 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... |