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;
const int N = 1e6 + 1;
char c[N];
int now = 0, idx = 0, d[N], anc[N][21], p[N];
void Init() {
now = idx = 0;
}
void TypeLetter(char L) {
idx++;
d[idx] = d[now] + 1;
anc[idx][0] = now;
for (int i = 1; i <= 20; i++) anc[idx][i] = anc[anc[idx][i - 1]][i - 1];
c[idx] = L;
p[idx] = idx;
now = idx;
}
void UndoCommands(int U) {
idx++;
p[idx] = p[idx - U - 1];
now = p[idx];
}
char GetLetter(int P) {
P++;
int u = p[now];
for (int i = 20; i >= 0; i--) if (d[anc[u][i]] >= P) u = anc[u][i];
return c[u];
}
/*
int main(){
Init();
TypeLetter('a');
TypeLetter('b') ;
cout << GetLetter(1) << '\n';
TypeLetter('d');
UndoCommands(2);
UndoCommands(1) ;
cout << GetLetter(2) << '\n';
TypeLetter('e');
UndoCommands(1);
UndoCommands(5) ;
TypeLetter('c') ;
cout << GetLetter(2) << '\n';
UndoCommands(2);
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... |