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>
#define ll long long
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int N = int(1e6) + 1;
const int logN = 21;
int cur, p[N][logN], ver[N], len[N];
char c[N];
void Init() {cur = 0;}
void TypeLetter(char ch) {
ver[cur] = cur, c[cur] = ch;
p[cur][0] = cur? cur - 1: cur;
len[cur] = len[p[cur][0]] + 1;
for(int i = 1; i < logN; ++i) p[cur][i] = p[p[cur][i - 1]][i - 1];
++cur;
}
void UndoCommands(int k) {
ver[cur] = ver[cur - k - 1];
len[cur] = len[ver[cur]];
c[cur] = c[ver[cur]];
++cur;
}
char GetLetter(int k) {
int pos = ver[cur - 1];
k = len[pos] - k - 1;
for(int i = logN - 1; i >= 0; --i)
if((k >> i) & 1) pos = p[pos][i];
return c[pos];
}
//int main()
//{
// ios_base::sync_with_stdio(0);
// cin.tie(0), cout.tie(0);
// if(fopen("test.inp", "r")) {
// freopen("test.inp", "r", stdin);
// freopen("test.out", "w", stdout);
// }
// Init();
// TypeLetter('a');// a
// TypeLetter('b');// ab
// cout << GetLetter(1) << '\n';// b ab
// TypeLetter('d');// abd
// UndoCommands(2);// a
// UndoCommands(1);// abd
// cout << GetLetter(2) << '\n';// d abd
// TypeLetter('e');// abde
// UndoCommands(1);// abd
// UndoCommands(5);// ab
// TypeLetter('c');// abc
// cout << GetLetter(2) << '\n';// c abc
// UndoCommands(2);// abd
// cout << GetLetter(2) << '\n';// d abd
//}
# | 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... |