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;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int t[1000000][26],par[1000000][32],co=1,lev[1000000];
vi v;
char c[1000000];
void Init()
{
v.pb(0);
for(int i=0;i<32;++i)
par[0][i]=0;
lev[0]=0;
}
void TypeLetter(char L)
{
if(t[v.back()][L-'a']==0)
{
t[v.back()][L-'a']=co;
par[co][0]=v.back();
c[co]=L;
lev[co]=lev[v.back()]+1;
for(int i=1;i<32;++i)
par[co][i]=par[par[co][i-1]][i-1];
v.pb(co);
co++;
}
else
v.pb(t[v.back()][L-'a']);
}
void UndoCommands(int U)
{
v.pb(v[v.size()-U-1]);
}
char GetLetter(int P)
{
P++;
int p=lev[v.back()]-P,cur=v.back(),b=0;
while((1LL<<b)<=p)
{
if(bit(p,b))
cur=par[cur][b];
b++;
}
return(c[cur]);
}
# | 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... |