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;
int currNode, p, i, query;
vector<int> commands;
int up[1000005][21];
typedef struct node {
int children[26];
char letter;
int dep;
node() {
fill(children, children+26, -1);
};
} node;
vector<node> trie;
void Init() {
currNode = 0;
trie.emplace_back();
trie[0].letter = 'a';
trie[0].dep = -1;
commands.push_back(0);
for (i=0; i < 21; ++i) {
up[0][i] = 0;
}
}
void TypeLetter(char L) {
p = currNode;
if (trie[currNode].children[L-'a'] == -1) {
trie[currNode].children[L-'a'] = trie.size();
trie.emplace_back();
}
currNode = trie[currNode].children[L-'a'];
trie[currNode].letter = L;
up[currNode][0] = p;
trie[currNode].dep = trie[p].dep+1;
for (i=1; i < 21; ++i) {
up[currNode][i] = up[up[currNode][i-1]][i-1];
}
commands.push_back(currNode);
}
void UndoCommands(int U) {
currNode = commands[(int)commands.size()-1-U];
commands.push_back(currNode);
}
char GetLetter(int P) {
P = trie[currNode].dep-P;
query = currNode;
for (i=0; i < 21 && P > 0; ++i) {
if (P & 1) {
query = up[query][i];
}
P >>= 1;
}
return trie[query].letter;
}
# | 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... |