This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
struct node{
char t;
int x,len;
}s[1000000];
int a[1000000][20],sz,cnt;
char b[1000000];
void Init() {}
void TypeLetter(char L){
int p=0;
if(sz)p=s[sz-1].len;
s[sz++]={L,cnt++,p+1};
b[cnt-1]=L;
if(sz>1){
a[cnt-1][0]=s[sz-2].x;
for(int i=1;i<20;i++)a[cnt-1][i]=a[a[cnt-1][i-1]][i-1];
}
/*
for(int i=0;i<sz;i++)printf("%c,%d,%d ",s[i].t,s[i].x,s[i].len);
puts("");
int x=s[sz-1].x;
do{
printf("%c ",b[x]);
x=a[x][0];
}while(x);
puts("");*/
}
void UndoCommands(int U) {
s[sz]=s[sz-U-1];
sz++;
/*
for(int i=0;i<sz;i++)printf("%c,%d,%d ",s[i].t,s[i].x,s[i].len);
puts("");
int x=s[sz-1].x;
do{
printf("%c ",b[x]);
x=a[x][0];
}while(x);
puts("");*/
}
char GetLetter(int P) {
int x=s[sz-1].x;
P=s[sz-1].len-P;
for(int i=19;i>=0;i--){
if(P>(1<<i)){
P-=(1<<i);
x=a[x][i];
}
}
return b[x];
}
# | 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... |