# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
820150 | BT21tata | Crayfish scrivener (IOI12_scrivener) | C++17 | 0 ms | 0 KiB |
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;
int que, up[1000006][21], len[1000006];
char c[1000006];
void Init() {}
void TypeLetter(char L)
{
que++;
c[que]=L;
up[que][0]=que-1;
len[que]=len[que-1]+1;
for(int i=1; i<21; i++)
up[que][i]=up[up[que][i-1]][i-1];
}
void UndoCommands(int U)
{
que++;
len[que]=len[que-1-U];
c[que]=c[que-1-U]
for(int i=0; i<21; i++)
up[que][i]=up[que-1-U][i];
}
char GetLetter(int p)
{
p=len[que]-1-p;
int cur=que;
for(int i=20; i>=0; i--)
{
if(p-(1<<i)>=0)
{
p-=(1<<i);
cur=up[cur][i];
}
}
return c[cur];
}