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 all(a) (a).begin()
#define ff first
#define ss second
#define ll long long
template<typename T>
int len(T &a){
return a.size();
}
const int maxn = 1e6;
#ifdef LOCAL
template<typename T>
void out(T a){
for(auto u : a) cout << u << ' ';
cout << endl;
}
#else
#define out(...)
#endif
struct tree{
struct node{
int sz = 0;
char let;
vector<int> par;
node () {}
node (char c) : let(c), par(20){}
};
vector<node> t;
int cur = 0;
tree (){ t.resize(maxn);}
void push(int fr, char x){
t[cur] = node(x);
if(fr == -1) t[cur].sz = 1;
else{
t[cur].par[0] = fr;
for(int i = 1; i < 20; i ++){
t[cur].par[i] = t[t[cur].par[i - 1]].par[i - 1];
}
t[cur].sz = t[fr].sz + 1;
}
cur ++;
}
int len(){return cur;}
char getkth(int i, int k){
k = t[i].sz - k - 1;
for(int j = 0; j < 20; j ++){
if((1 << j) & k){
i = t[i].par[j];
}
}
return t[i].let;
}
} tr;
vector<int> ops;
int cur = 0;
void Init(){
ops.push_back({-1});
}
int cnt = 0;
void TypeLetter(char c){
tr.push(ops.back(), c);
ops.push_back(tr.len() - 1);
}
void UndoCommands(int u){
ops.push_back(ops[len(ops) - u - 1]);
}
char GetLetter(int p){
return tr.getkth(ops.back(), p);
}
# | 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... |