#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
vector<ll> cmd = {0}; // cmd[i] -> index of the cur node after the ith command
vector<char> node; // node value
vector<vector<ll>> par(2e6, vector<ll>(20)); // node parent (binary jumping)
ll n = 0; // nodes created
void Init() {}
void TypeLetter(char ch) {
par[n][0] = cmd[cmd.size()-1];
cmd.push_back(n);
node.push_back(ch);
for(ll j = 1; j < 20; j++) par[n][j] = par[par[n][j-1]][j-1];
n++;
}
void UndoCommands(int k) {
cmd.push_back(cmd[cmd.size()-1-k]);
}
char GetLetter(int k) {
k -= cmd[cmd.size()-1];
ll j = 19;
ll bru = cmd[cmd.size()-1];
while(j > -1) {
if (pow(2, j) <= k) {
bru = par[bru][j];
k -= pow(2, j);
}
j--;
}
return node[bru];
}
# | 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... |