Submission #70929

#TimeUsernameProblemLanguageResultExecution timeMemory
70929FLDutchmanCrayfish scrivener (IOI12_scrivener)C++14
100 / 100
910 ms99476 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)

char nodes[1000100]; int sz[1000100];
int lift[1000100][21];
int numVersions = 0;

int insert(int l, char c){
    int ver = numVersions++;
    nodes[ver] = c;
    sz[ver] = sz[l]+1;
    //cerr<<getsz(l) << " " << l->lift.size() << endl;
    int i = 0;
    while(true){
        //cout<<getsz(l)<<endl;
        lift[ver][i] = l;
        //cout<<nl->lift.size()<<endl;
        if(lift[l][i] == -1) return ver;
        l = lift[l][i++];
    }    
}

char getletter(int l, int i){
    //cerr<<getsz(l) << " " << l->lift.size() << endl;
    FOR(k, 0, 21) if(i & (1<<k)) l = lift[l][k]; 
    return nodes[l];
}


void Init() {
    sz[0] = nodes[0] = 0;
    numVersions = 1; 
    FOR(i, 0, 1000100) FOR(j, 0, 21) lift[i][j] = -1;
}

void TypeLetter(char L) {
    //for(auto l : v) cout << getsz(l) << " " << (l ?  to_string(l->lift.size()) :"") << endl;
    insert(numVersions-1, L);
}

void UndoCommands(int U) {
    int o = numVersions - 1 - U, n = numVersions++;
    nodes[n] = nodes[o];
    sz[n] = sz[o];
    FOR(i, 0, 21) lift[n][i] = lift[o][i];
}

char GetLetter(int P) {
    int v = numVersions - 1;
    return getletter(v, sz[v]-1 - P);
}
#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...