Submission #910047

#TimeUsernameProblemLanguageResultExecution timeMemory
910047MackerCrayfish scrivener (IOI12_scrivener)C++17
100 / 100
525 ms156228 KiB
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")

struct node {
    char c;
    array<node*, 22> par;
    int len;
};
typedef node* pnode;

pnode cur;
vector<pnode> undo;

void Init() {
    cur = new node();
    cur->len = -1;
    undo.push_back(cur);
}

void TypeLetter(char L) {
    pnode tmp = new node();
    tmp->par[0] = cur;
    for (int i = 1; i < 22; i++) {
        if(tmp->par[i - 1] == NULL) break;
        tmp->par[i] = tmp->par[i - 1]->par[i - 1];
    }
    tmp->c = L;
    tmp->len = cur->len + 1;
    cur = tmp;
    undo.push_back(cur);
}

void UndoCommands(int U) {
    pnode tmp = undo[undo.size() - U - 1];
    cur = tmp;
    undo.push_back(cur);
}

char GetLetter(int P) {
    pnode tmp = cur;
    int x = tmp->len - P;
    for (int i = 0; i < 22; i++) {
        if(x & (1 << i)){
            tmp = tmp->par[i];
        }
    }
    return tmp->c;
}
#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...