#include <bits/stdc++.h>
using namespace std;
int to[1000005][26];
int up[1000005][21];
int dep[1000005];
int nw=1;
char val[1000005];
vector<int> pos={0};
void Init() {dep[0]=-1;}
void TypeLetter(char L) {
int c=L-'a';
if(to[pos.back()][c]==0){
to[pos.back()][c]=nw;
val[nw]=L;
up[nw][0]=pos.back();
for(int j=1;j<=20;j++){
up[nw][j]=up[up[nw][j-1]][j-1];
}
dep[nw]=dep[pos.back()]+1;
pos.push_back(nw);
nw++;
}
else {
pos.push_back(to[pos.back()][c]);
}
}
void UndoCommands(int U) {
pos.push_back(pos[pos.size()-1-U]);
}
char GetLetter(int P) {
int raiseby=dep[pos.back()]-P;
//~ for(auto it: pos)cout<<it<<" ";
//~ cout<<endl;
//~ printf("raiseby %d\n", raiseby);
int cur=pos.back();
for(int i=0;i<=20;i++){
if((1<<i)&raiseby){
cur=up[cur][i];
}
}
return val[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... |