#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-Ofast")
#ifndef wambule
// #include ".h"
#else
#endif
const int N = 1000006;
const int L = 21;
struct ovo {
vector<ovo*> v;
ovo *up[L];
int dt;
char c;
ovo() {}
ovo(ovo *op, char _c) {
c = _c;
dt = op->dt + 1;
v.clear();
up[0] = op;
for(int i = 1; i < L; ++i) {
up[i] = up[i - 1];
if(up[i] != NULL) up[i] = up[i]->up[i - 1];
}
}
ovo* A(char c) {
v.push_back(new ovo(this, c));
return *(--v.end());
}
} rt, *dg;
vector<ovo*> v;
void Init() {
rt.c = ' ';
rt.dt = -1;
rt.v.clear();
for(int i = 0; i < L; ++i) {
rt.up[i] = NULL;
}
dg = &rt;
}
void TypeLetter(char c) {
dg = dg->A(c);
v.push_back(dg);
}
void UndoCommands(int x) {
dg = v[(int)v.size() - 1 - x];
v.push_back(dg);
}
char GetLetter(int id) {
ovo *x = dg;
for(int i = L - 1; i >= 0; --i) {
if(x->up[i] != NULL && x->up[i]->dt >= id) {
x = x->up[i];
}
}
#ifdef wambule
cout << "[:] " << x->c << endl;
#endif
return x->c;
}
#ifdef wambule
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
Init();
TypeLetter('a');
TypeLetter('b');
GetLetter(1);
TypeLetter('d');
UndoCommands(2);
UndoCommands(1);
GetLetter(2);
TypeLetter('e');
UndoCommands(1);
UndoCommands(5);
TypeLetter('c');
GetLetter(2);
UndoCommands(2);
GetLetter(2);
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
2 ms |
748 KB |
Output is correct |
3 |
Correct |
2 ms |
748 KB |
Output is correct |
4 |
Correct |
2 ms |
1004 KB |
Output is correct |
5 |
Correct |
2 ms |
748 KB |
Output is correct |
6 |
Correct |
2 ms |
1260 KB |
Output is correct |
7 |
Correct |
2 ms |
1132 KB |
Output is correct |
8 |
Correct |
2 ms |
1004 KB |
Output is correct |
9 |
Correct |
2 ms |
1004 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
627 ms |
139592 KB |
Output is correct |
2 |
Correct |
651 ms |
153416 KB |
Output is correct |
3 |
Correct |
498 ms |
149960 KB |
Output is correct |
4 |
Correct |
479 ms |
117448 KB |
Output is correct |
5 |
Correct |
772 ms |
125388 KB |
Output is correct |
6 |
Correct |
639 ms |
162040 KB |
Output is correct |
7 |
Correct |
621 ms |
80376 KB |
Output is correct |
8 |
Correct |
604 ms |
124252 KB |
Output is correct |
9 |
Correct |
746 ms |
170312 KB |
Output is correct |
10 |
Correct |
285 ms |
116168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
984 ms |
117896 KB |
Output is correct |
2 |
Execution timed out |
1079 ms |
101588 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |