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>
#define MAX_N 1000004
using namespace std;
struct node{
int par;
int sqpar;
int len;
char c;
};
node trie[MAX_N];
int sz;
const int sqrt = 800;
void init_node(int cur,int par,char c)
{
trie[cur].par = par;
trie[cur].c = c;
trie[cur].len = trie[par].len+1;
if(trie[cur].len%sqrt == 0)
trie[cur].sqpar = par;
else
trie[cur].sqpar = trie[par].sqpar;
return;
}
int get_ancestor(int cur,int x)
{
while(trie[trie[cur].sqpar].len >= x)
cur = trie[cur].sqpar;
while(trie[cur].len > x)
cur = trie[cur].par;
return cur;
}
void Init()
{
init_node(0,0,'-');
trie[0].len = 0;
sz = 1;
return;
}
void TypeLetter(char L)
{
init_node(sz,sz-1,L);
sz++;
return;
}
void UndoCommands(int U)
{
trie[sz] = trie[sz-U-1];
sz++;
return;
}
char GetLetter(int P)
{
// cout << "here " << P << " " << sz-1 << " " << trie[sz-1].len << " " << get_ancestor(sz-1,trie[sz-1].len-P-1) << endl;
return trie[get_ancestor(sz-1,P+1)].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... |