This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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();
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 (stderr)
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("");
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |