This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
const int lgMAXN = 20;
const int MAXN = 1 << 20;
int len;
int arr[MAXN];
int sparse[MAXN][lgMAXN];
void Init() {
len = 0;
}
void TypeLetter(char L) {
arr[++len] = L;
sparse[len][0] = len;
for(int i=1; i<lgMAXN; ++i)
if(sparse[len][i-1] == 0) sparse[len][i] = 0;
else sparse[len][i] = sparse[sparse[len][i-1]-1][i-1];
}
void UndoCommands(int U) {
arr[++len] = -U;
for(int i=0; i<lgMAXN; ++i)
sparse[len][i] = sparse[len-U-1][i];
}
char GetLetter(int P) {
int c = 0, idx = len;
for(int i=lgMAXN-1; i>=0; --i)
if(sparse[idx][i])
{
c += (1<<i);
idx = sparse[idx][i]-1;
}
int ans = len;
for(int i=lgMAXN-1; i>=0; --i)
if((c-P)&(1<<i))
ans = sparse[ans][i]-1;
return arr[ans+1];
}
# | 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... |