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;
char arr[1000001];
int len[1000001];
map<int,int> mp;
int op = 0 , root = 0 , node = 0;
int lift[1000001][20];
void Init(){
mp[op] = root;
}
void TypeLetter(char l){
node++;
lift[node][0] = root;
for(int i = 1;i<20;i++){
lift[node][i] = lift[lift[node][i-1]][i-1];
}
len[node] = len[root]+1;
root = node;
op++;
mp[op] = root;
arr[root] = l;
}
void UndoCommands(int u){
mp[op+1] = mp[op-u];
root = mp[++op];
}
char GetLetter(int p){
int cc = root;
p = (p+1)-len[root];
for(int i = 19;i>=0;i--){
if(p>=(1<<i)){
p-=(1<<i);
cc =lift[cc][i];
}
}
return arr[cc];
}
/*int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
Init();
TypeLetter('a');
cout<<root<<"\n";
TypeLetter('b');
cout<<root<<"\n";
cout<<GetLetter(1)<<"\n";
TypeLetter('d');
cout<<root<<"\n";
UndoCommands(2);
cout<<root<<"\n";
UndoCommands(1);
cout<<root<<"\n";
cout<<GetLetter(2)<<"\n";
}*/
# | 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... |