#include <bits/stdc++.h>
using namespace std;
const int mx = 1e3 + 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);
}
};
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(nullptr, L, !n ? 0 : N[n-1].i + 1);
//puts("f2");
node &x = N[n];
//puts("f3");
x.p[0] = (!n ? nullptr : &N[n-1]);
//puts("f4");
for(int j = 1; j < lg; j++){
printf("");
if(x.p[j-1] != nullptr) x.p[j] = x.p[j-1] -> p[j-1];
else break;
}
//puts("f5");
x.c = &x;
//N[n].show();
++n;
}
void UndoCommands(int U) {
//printf("Undo(%d)\n",U);
N.emplace_back();
if(U == n){
N[n] = node(nullptr, '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] = &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("");
^
scrivener.cpp:34:18: warning: zero-length gnu_printf format string [-Wformat-zero-length]
printf("");
^
scrivener.cpp: In function 'void UndoCommands(int)':
scrivener.cpp:49:15: warning: unused variable 'x' [-Wunused-variable]
node &x = N[n];
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
444 KB |
Output is correct |
4 |
Correct |
2 ms |
456 KB |
Output is correct |
5 |
Correct |
2 ms |
456 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
576 KB |
Output is correct |
9 |
Correct |
2 ms |
576 KB |
Output is correct |
10 |
Correct |
2 ms |
576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
576 KB |
Output is correct |
2 |
Runtime error |
3 ms |
804 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
804 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
1312 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
1364 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |