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>
#define N 1000005
#define K 21
using namespace std;
struct node{
int par,cnt;
char last;
node(){
par = cnt = 0;
last = '#';
}
};
node sp[N][K];
int cnt = 0;
void Init() {}
void TypeLetter(char l) {
sp[cnt+1][0].par = cnt;
sp[cnt+1][0].cnt = 1;
sp[cnt+1][0].last = l;
cnt++;
for(int j = 1;j<K;j++){
sp[cnt][j].par = sp[sp[cnt][j-1].par][j-1].par;
sp[cnt][j].cnt = sp[cnt][j-1].cnt + sp[sp[cnt][j-1].par][j-1].cnt;
sp[cnt][j].last = sp[sp[cnt][j-1].par][j-1].last;
}
}
void UndoCommands(int u) {
sp[cnt+1][0].par = cnt - u;
sp[cnt+1][0].cnt = 0;
sp[cnt+1][0].last = '#';
cnt++;
for(int j = 1;j<K;j++){
sp[cnt][j].par = sp[sp[cnt][j-1].par][j-1].par;
sp[cnt][j].cnt = sp[cnt][j-1].cnt + sp[sp[cnt][j-1].par][j-1].cnt;
sp[cnt][j].last = sp[sp[cnt][j-1].par][j-1].last;
}
}
char GetLetter(int p) {
int tot = sp[cnt][K-1].cnt;
int needed = tot - p;
int tmp = cnt;
for(int i = K-1;i>=0;i--){
if(sp[tmp][i].cnt < needed){
needed -= sp[tmp][i].cnt;
tmp = sp[tmp][i].par;
}
}
return sp[tmp][0].last;
}
# | 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... |