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 <iostream>
#include <vector>
#include <cassert>
using namespace std;
int upr[1000001][21];
char ch[1000001];
int len[1000001];
int cnt = 0;
void Init()
{
cnt = 1;
for (int i = 0; i < 21; i++) upr[0][i] = 0;
}
void TypeLetter(char L)
{
ch[cnt] = L;
len[cnt] = len[cnt - 1] + 1;
upr[cnt][0] = cnt - 1;
for (int i = 1; i < 21; i++) upr[cnt][i] = upr[upr[cnt][i - 1]][i - 1];
cnt++;
}
void UndoCommands(signed U)
{
int st = cnt - U - 1;
ch[cnt] = ch[st];
for (int i = 0; i < 21; i++) upr[cnt][i] = upr[st][i];
len[cnt] = len[st];
cnt++;
}
char GetLetter(signed P)
{
int u = len[cnt - 1] - 1 - P;
int c = cnt - 1;
for (int i = 0; i < 21; i++)
{
if (u & (1<<i))
{
c = upr[c][i];
}
}
return ch[c];
}
# | 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... |