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 N = 1000 * 1000 + 5, LG = 21;
char last = 0;
int ind = 0;
string s = "";
int sz[N];
int pos[N];
char c[N];
int par[N][LG];
void Init() {
for (int i = 0; i < N; i++) {
pos[i] = i;
}
}
void TypeLetter(char L) {
ind++;
sz[ind] = sz[ind - 1] + 1;
c[ind] = L;
pos[ind] = ind;
par[ind][0] = pos[ind - 1];
for (int j = 1; j < LG; j++) {
par[ind][j] = par[par[ind][j - 1]][j - 1];
}
}
void UndoCommands(int U) {
ind++;
pos[ind] = pos[ind - U - 1];
sz[ind] = sz[ind - U - 1];
}
char GetLetter(int P) {
int v = pos[ind];
int k = sz[ind] - P - 1;
// cout << "71 " << k << endl;
for (int j = LG - 1; j >= 0; j--) {
if (k >= (1 << j)) {
v = par[v][j];
k -= 1 << j;
}
}
return c[v];
}
# | 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... |