Submission #1229973

#TimeUsernameProblemLanguageResultExecution timeMemory
1229973AMel0nCrayfish scrivener (IOI12_scrivener)C++20
100 / 100
661 ms244008 KiB
#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


// everything is 1-indexed

vector<int> cmd = {0};  // cmd[i] -> idx of cur node    after ith command
vector<int> len = {0};  // len[i] -> len of cur string  after ith command
vector<char> node = {' '}; // node value
vector<vector<int>> par(2e6, vector<int>(20)); // node parent (binary jumping)

void Init() {}

void TypeLetter(char ch) {
    node.push_back(ch);
    len.push_back(len[cmd.back()] + 1);
    par[node.size()-1][0] = cmd.back();
    cmd.push_back(node.size()-1);
    for(int j = 1; j < 20; j++) par[node.size()-1][j] = par[par[node.size()-1][j-1]][j-1];
}

void UndoCommands(int k) {
    cmd.push_back(cmd[cmd.size()-1-k]);
}

char GetLetter(int k) {
    k = len[cmd.back()] - 1 - k;
    int j = 19;
    int bru = cmd.back();
    while(j > -1) {
        if (pow(2, j) <= k) {
            bru = par[bru][j];
            k -= pow(2, j);
        }
        j--;
    }
    return node[bru];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...