# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1015566 | parsadox2 | 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;
const int N = 1e6 + 10 , Lg = 20;
int pnt[N] , now , safar;
struct TRIE{
struct NODE{
int par[Lg];
char c;
int dis;
} t[N];
int pos = 1;
void Build()
{
pos = 1;
t[0].dis = -1;
t[0].c = 'P';
}
void Add(int v , char c)
{
t[pos].par[0] = v;
t[pos].dis = t[v].dis + 1;
for(int i = 1 ; i < Lg ; i++)
t[pos].par[i] = t[t[pos].par[i - 1]].par[i - 1];
t[pos].c = c;
pos++;
}
char Get(int v , int h)
{
int dis = t[v].dis - h;
for(int i = 0 ; i < Lg ; i++) if((dis >> i) & 1)
v = t[v].par[i];
return t[v].c;
}
} trie;
void Init()
{
trie.Build();
pnt[0] = 0;
now = 1;
}
void TypeLetter(char c)
{
pnt[now] = trie.pos;
//cout << now << " : " << pnt[now] << endl;
trie.Add(pnt[now - 1] , c);
now++;
}
void UndoCommands(int l)
{
pnt[now] = pnt[now - 1 - l];
//cout << now << " : " << pnt[now] << endl;
now++;
}
char GetLetter(int p)
{
//cout << "ASK : " << pnt[now] << endl;
return trie.Get(pnt[now - 1] , p);
}