#include <bits/stdc++.h>
using namespace std;
const int mx = 1e3 + 5;
const int lg = 20;
struct node{
node(){}
node(int c, char x, int i) : c(c),x(x),i(i) {
memset(p,-1,sizeof(p));
}
int p[lg], c;
char x;
int i;
void show(){
printf("x = %c, i = %d, c = %d\n",x,i,c);
}
};
vector<node> N;
int n;
void Init() {
}
void TypeLetter(char L) {
//printf("Type(%c)\n",L);
printf("");
N.emplace_back();
//puts("f1");
N[n] = node(0, L, !n ? 0 : N[n-1].i + 1);
//puts("f2");
node &x = N[n];
//puts("f3");
x.p[0] = (!n ? -1 : n-1);
//puts("f4");
for(int j = 1; j < lg; j++){
printf("");
//printf("j = %d\n",j);
if(x.p[j-1] != -1) x.p[j] = N[x.p[j-1]].p[j-1];
else break;
}
//puts("f5");
x.c = n;
//N[n].show();
++n;
}
void UndoCommands(int U) {
//printf("Undo(%d)\n",U);
N.emplace_back();
if(U == n){
N[n] = node(-1, 'U', -1);
node &x = N[n];
++n;
return;
}
node p = N[n - 1 - U];
N[n] = node(p.c, 'U', p.i);
node &x = N[n];
x.p[0] = n - 1 - U;
for(int j = 1; j < lg; j++){
if(x.p[j-1] != -1) x.p[j] = N[x.p[j-1]].p[j-1];
}
//N[n].show();
++n;
}
char GetLetter(int P) {
//printf("Get(%d)\n",P);
node b = N[n-1];
if(b.i < P) puts("BAAM!");
for(int j = lg; j >= 0; j--){
if(b.i == P) return N[b.c].x;
if(b.p[j] != -1 && N[b.p[j]].i >= P) b = N[b.p[j]];
}
//printf("bi : %d\n",b->i);
//puts("asdf");
return b.i == P ? N[b.c].x : N[N[b.p[0]].c].x;
}
Compilation message
scrivener.cpp: In function 'void TypeLetter(char)':
scrivener.cpp:26:14: warning: zero-length gnu_printf format string [-Wformat-zero-length]
printf("");
^
scrivener.cpp:36:18: warning: zero-length gnu_printf format string [-Wformat-zero-length]
printf("");
^
scrivener.cpp: In function 'void UndoCommands(int)':
scrivener.cpp:52:15: warning: unused variable 'x' [-Wunused-variable]
node &x = N[n];
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
480 KB |
Output is correct |
3 |
Correct |
2 ms |
480 KB |
Output is correct |
4 |
Correct |
2 ms |
480 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
6 |
Correct |
2 ms |
584 KB |
Output is correct |
7 |
Correct |
2 ms |
608 KB |
Output is correct |
8 |
Correct |
2 ms |
608 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
636 KB |
Output is correct |
2 |
Correct |
2 ms |
636 KB |
Output is correct |
3 |
Correct |
2 ms |
636 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
644 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
652 KB |
Output is correct |
8 |
Correct |
2 ms |
656 KB |
Output is correct |
9 |
Correct |
2 ms |
660 KB |
Output is correct |
10 |
Correct |
2 ms |
668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
928 KB |
Output is correct |
2 |
Correct |
4 ms |
1128 KB |
Output is correct |
3 |
Correct |
4 ms |
1220 KB |
Output is correct |
4 |
Correct |
4 ms |
1628 KB |
Output is correct |
5 |
Correct |
6 ms |
1628 KB |
Output is correct |
6 |
Correct |
7 ms |
1688 KB |
Output is correct |
7 |
Correct |
4 ms |
1688 KB |
Output is correct |
8 |
Correct |
4 ms |
1732 KB |
Output is correct |
9 |
Correct |
5 ms |
1756 KB |
Output is correct |
10 |
Correct |
4 ms |
1780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1012 ms |
97588 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1082 ms |
102416 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |