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];
void Init() {
now = idx = 0;
}
void TypeLetter(char L) {
idx++;
d[idx] = d[now] + 1;
anc[idx][0] = now;
int r = 0;
while ((1 << r) < d[idx]) r++;
for (int i = 1; i <= r; i++) anc[idx][i] = anc[anc[idx][i - 1]][i - 1];
c[idx] = L;
now = idx;
}
void UndoCommands(int U) {
idx++;
int p = idx - U - 1;
d[idx] = d[p];
anc[idx][0] = p;
int r = 0;
while ((1 << r) < d[idx]) r++;
for (int i = 1; i <= r; i++) anc[idx][i] = anc[anc[idx][i - 1]][i - 1];
now = idx;
}
char GetLetter(int P) {
P++;
int u = 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... |