#include <bits/stdc++.h>
using namespace std;
static const int MAXN = (int) 1e6;
static int anc_let[20][MAXN + 1], anc[20][MAXN + 1];
static int len[MAXN + 1], cur, sz;
static char let[MAXN + 1];
void Init() {
cur = sz = 0;
len[0] = 0;
}
void TypeLetter(char L) {
sz++;
let[sz] = L;
len[sz] = len[cur] + 1;
anc_let[0][sz] = cur;
anc[0][sz] = cur;
for(int bit = 1; bit < 20; bit++) {
anc[bit][sz] = anc[bit - 1][anc[bit - 1][sz]];
anc_let[bit][sz] = anc_let[bit - 1][anc_let[bit - 1][sz]];
}
cur = sz;
}
void UndoCommands(int U) {
int last = cur;
for(int bit = 0; bit < 20; bit++) {
if(U & (1 << bit)) {
cur = anc[bit][cur];
}
}
sz++;
let[sz] = let[cur];
len[sz] = len[cur];
cur = anc_let[0][cur];
anc[0][sz] = last;
anc_let[0][sz] = cur;
for(int bit = 1; bit < 20; bit++) {
anc[bit][sz] = anc[bit - 1][anc[bit - 1][sz]];
anc_let[bit][sz] = anc_let[bit - 1][anc_let[bit - 1][sz]];
}
cur = sz;
}
char GetLetter(int P) {
int ans = cur;
P = len[cur] - P - 1;
for(int bit = 0; bit < 20; bit++) {
if(P & (1 << bit)) {
ans = anc_let[bit][ans];
}
}
return let[ans];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
888 KB |
Output is correct |
2 |
Correct |
4 ms |
1144 KB |
Output is correct |
3 |
Correct |
4 ms |
1400 KB |
Output is correct |
4 |
Correct |
4 ms |
1400 KB |
Output is correct |
5 |
Correct |
4 ms |
1272 KB |
Output is correct |
6 |
Correct |
4 ms |
1400 KB |
Output is correct |
7 |
Correct |
5 ms |
1272 KB |
Output is correct |
8 |
Correct |
4 ms |
1400 KB |
Output is correct |
9 |
Correct |
4 ms |
1400 KB |
Output is correct |
10 |
Correct |
4 ms |
1400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
446 ms |
116024 KB |
Output is correct |
2 |
Correct |
560 ms |
141704 KB |
Output is correct |
3 |
Correct |
600 ms |
145324 KB |
Output is correct |
4 |
Correct |
646 ms |
153340 KB |
Output is correct |
5 |
Correct |
468 ms |
134520 KB |
Output is correct |
6 |
Correct |
434 ms |
157560 KB |
Output is correct |
7 |
Execution timed out |
1083 ms |
136192 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
538 ms |
106348 KB |
Output is correct |
2 |
Correct |
700 ms |
91368 KB |
Output is correct |
3 |
Correct |
617 ms |
116924 KB |
Output is correct |
4 |
Correct |
553 ms |
100836 KB |
Output is correct |
5 |
Correct |
425 ms |
136180 KB |
Output is correct |
6 |
Correct |
504 ms |
140840 KB |
Output is correct |
7 |
Correct |
436 ms |
140776 KB |
Output is correct |
8 |
Execution timed out |
1042 ms |
118620 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |