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 N=1e6+55;
int trie[N*2][26];
char letter[N];
int p[N][22];
int a[N];
int l[N];
int node;
int cnt=1;
int k=1;
void Init()
{
node=cnt++;
}
int c,temp,nd;
void TypeLetter(char L)
{
c=L-'a';
temp=node;
if(trie[node][c]==0)
trie[node][c]=cnt++;
node=trie[node][c];
letter[node]=L;
a[k]=node;
l[k]=l[k-1]+1;
if(p[node][0]==0)
{
p[node][0]=temp;
for(int i=1;i<21;i++)
{
p[node][i]=p[p[node][i-1]][i-1];
if(p[node][i]==0)
break;
}
}
k++;
}
void UndoCommands(int U)
{
node=a[k-U-1];
l[k]=l[k-U-1];
a[k]=node;
k++;
}
char GetLetter(int P)
{
P=l[k-1]-P-1;
nd=node;
for(int i=20;i>=0;i--)
{
if((P&(1<<i)))
nd=p[nd][i];
}
return letter[nd];
}
# | 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... |