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>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
vector<char> v[1000005];
const int lg=19;
int Len[1000005],pa[1000005],up[lg+1][1000005],ti[1000005],t;
void Init(){
t=0,Len[0]=-1;
}
void TypeLetter(char L)
{
int prev=ti[t];
++t;
ti[t]=t,Len[t]=Len[prev]+1;
if(v[pa[prev]].size()==Len[t]-Len[pa[prev]])
v[pa[prev]].pb(L),pa[t]=pa[prev];
else
{
up[0][t]=pa[prev],pa[t]=t,v[t].pb(L);
for(int i=1;i<=lg;++i)
up[i][t]=up[i-1][up[i-1][t]];
}
}
void UndoCommands(int U)
{
++t,ti[t]=ti[t-U-1],Len[t]=Len[t-U-1];
}
char GetLetter(int P)
{
int x=pa[ti[t]];
for(int i=lg;i>=0;--i)
if(Len[up[i][x]]>P)
x=up[i][x];
if(Len[x]>P)
x=up[0][x];
return v[x][P-Len[x]];
}
Compilation message (stderr)
scrivener.cpp: In function 'void TypeLetter(char)':
scrivener.cpp:29:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[pa[prev]].size()==Len[t]-Len[pa[prev]])
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |