This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
//#include "grader.h"
using namespace std;
typedef long long int ll;
const int MAXN = 1e6 + 5;
struct node
{
node *par[20];
char c;
int len = 1;
};
node *arr[MAXN];
int cnt = -1;
node *add(char x, node *cur) {
node *ret = new node;
if (cur != NULL)
ret->len = cur->len + 1;
ret->c = x;
ret->par[0] = cur;
for (int i = 1; i < 20; i++) {
if (ret->par[i-1] != NULL)
ret->par[i] = ret->par[i - 1]->par[i - 1];
else
break;
}
return ret;
}
void Init() {
}
void TypeLetter(char c) {
cnt++;
if (cnt == 0)
arr[cnt] = add(c, NULL);
else
arr[cnt] = add(c, arr[cnt-1]);
}
void UndoCommands(int u) {
cnt++;
arr[cnt] = arr[cnt - u - 1];
}
char GetLetter(int k) {
node *tmp = arr[cnt];
k = tmp->len - k - 1;
for (int i = 0; k != 0 && i < 20; i++) {
if (k & 1)
tmp = tmp->par[i];
k /= 2;
}
return tmp->c;
}
# | 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... |