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(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() {
N.reserve(mx);
}
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("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];
else break;
}
//N[n].show();
++n;
}
char GetLetter(int P) {
//printf("Get(%d)\n",P);
node b = N[n-1];
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 (stderr)
scrivener.cpp: In function 'void UndoCommands(int)':
scrivener.cpp:52:15: warning: unused variable 'x' [-Wunused-variable]
node &x = N[n];
^
# | 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... |