#include <bits/stdc++.h>
using namespace std;
static const int MAXN = (int) 1e6;
static int anc_let[MAXN + 1][20], anc[MAXN + 1][20];
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[sz][0] = cur;
anc[sz][0] = cur;
for(int bit = 1; bit < 20; bit++) {
anc[sz][bit] = anc[anc[sz][bit - 1]][bit - 1];
anc_let[sz][bit] = anc_let[anc_let[sz][bit - 1]][bit - 1];
}
cur = sz;
}
void UndoCommands(int U) {
int last = cur;
for(int bit = 0; bit < 20; bit++) {
if(U & (1 << bit)) {
cur = anc[cur][bit];
}
}
sz++;
let[sz] = let[cur];
len[sz] = len[cur];
cur = anc[cur][0];
anc[sz][0] = last;
anc_let[sz][0] = cur;
for(int bit = 1; bit < 20; bit++) {
anc[sz][bit] = anc[anc[sz][bit - 1]][bit - 1];
anc_let[sz][bit] = anc_let[anc_let[sz][bit - 1]][bit - 1];
}
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[ans][bit];
}
}
return let[ans];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
424 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
668 ms |
119392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
880 ms |
110564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |