#include <bits/stdc++.h>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const int LOG=21;
vector<vector<int>> parent;
vector<char> a;
vector<int> pos;
vector<int> dep;
int c=-1;
void Init() {
parent.push_back({});
for (int j = 0; j < LOG; j++) parent.back().push_back(0);
dep.push_back(0);
pos.push_back(0);
a.push_back(' ');
c=0;
}
void TypeLetter(char L) {
a.push_back(L);
parent.push_back({c});
pos.push_back(sz(a)-1);
dep.push_back(dep[c]+1);
c=sz(a)-1;
for (int j = 1; j < LOG; j++) parent.back().push_back(parent[parent[c][j-1]][j-1]);
}
void UndoCommands(int U) {
pos.push_back(pos[sz(pos)-U-1]);
c=pos.back();
}
char GetLetter(int P) {
int u=c;
P=dep[u]-(P+1);
for (int j = LOG-1; j >= 0; j--)
{
if(P&(1<<j)) u=parent[u][j];
}
return a[u];
}
# | 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... |