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 <iostream>
#define MAX 1000000
using namespace std;
char letter[MAX + 1];
int A[MAX + 1][21];
int back[MAX + 1]; // if undo, how far back to go, otherwise go back to current
int curr;
void Init() {
for (int i = 0; i <= MAX; i++) {
back[i] = i;
}
curr = 0;
}
void TypeLetter(char L) {
curr++;
letter[curr] = L;
int prev = back[curr - 1]; // previous index
A[curr][0] = prev;
for (int j = 1; j <= 20; j++) {
A[curr][j] = A[A[curr][j - 1]][j - 1];
}
}
void UndoCommands(int U) {
curr++;
back[curr] = back[curr - U - 1]; // position to go back to
}
char GetLetter(int P) {
P++;
int pos = back[curr];
for (int j = 20; j >= 0; j--) {
if (A[pos][j] >= P) {
pos = A[pos][j];
}
}
return letter[pos];
}
# | 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... |