#include <bits/stdc++.h>
using namespace std;
const int mx = 1e6 + 5;
const int lg = 20;
struct node{
node(){}
node(node *c, char x, int i) : c(c),x(x),i(i) {}
node *p[lg], *c;
char x;
int i;
void show(){
printf("x = %c, i = %d, c = %p\n",x,i,c);
}
};
node N[mx];
int n;
void Init() {
}
void TypeLetter(char L) {
//printf("Type(%c)\n",L);
printf("");
N[n] = node(nullptr, L, !n ? 0 : N[n-1].i + 1);
node &x = N[n];
x.p[0] = (!n ? nullptr : N + n - 1);
for(int j = 1; j < lg; j++){
if(x.p[j-1] != nullptr) x.p[j] = x.p[j-1] -> p[j-1];
else break;
}
x.c = &x;
//N[n].show();
++n;
}
void UndoCommands(int U) {
//printf("Undo(%d)\n",U);
node p = N[n - 1 - U];
N[n] = node(p.c, 'U', p.i);
node &x = N[n];
x.p[0] = &p;
for(int j = 1; j < lg; j++){
if(x.p[j-1]) x.p[j] = 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 b->c->x;
if(b->p[j] && b->p[j]->i >= P) b = b->p[j];
}
//printf("bi : %d\n",b->i);
//puts("asdf");
return b->i == P ? b->c->x : b->p[0]->c->x;
}
Compilation message
scrivener.cpp: In function 'void TypeLetter(char)':
scrivener.cpp:24:14: warning: zero-length gnu_printf format string [-Wformat-zero-length]
printf("");
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
532 KB |
Output is correct |
9 |
Correct |
2 ms |
536 KB |
Output is correct |
10 |
Correct |
2 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
676 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
824 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
34 ms |
14908 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
33 ms |
15312 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |