Submission #100311

#TimeUsernameProblemLanguageResultExecution timeMemory
100311naoai크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++14
100 / 100
953 ms146168 KiB
#include <bits/stdc++.h>

using namespace std;

const int sigma = 26;
const int nmax = 1e6 + 5;
const int logmax = 21;

int n, ind;
int p[nmax + 1];

int h[nmax + 1];
int fiu[nmax + 1][sigma + 1];
int d[nmax + 1][logmax + 1];

char ch[nmax + 1];

void Init() {
    n = 1;
    for (int i = 0; i < sigma; ++ i)
        fiu[1][i] = -1;

    ind = 0;
    p[0] = 1;
}

void TypeLetter(char L) {
    ++ ind;
    p[ind] = p[ind - 1];

    if (fiu[p[ind]][L - 'a'] == -1) {
        ++ n;
        fiu[p[ind]][L - 'a'] = n;
        h[n] = h[p[ind]] + 1;
        for (int i = 0; i < sigma; ++ i)
            fiu[n][i] = -1;

        p[ind] = n;
        ch[n] = L;
        d[n][0] = p[ind - 1];
        for (int i = 1; i < logmax; ++ i) {
            d[n][i] = d[d[n][i - 1]][i - 1];
        }
    } else {
        p[ind] = fiu[p[ind]][L - 'a'];
    }
}

void UndoCommands(int U) {
    ++ ind;
    p[ind] = p[ind - U - 1];
}

char GetLetter(int P) {
    int dif = h[p[ind]] - P - 1;
    int x = p[ind];

    for (int i = logmax - 1; i >= 0; -- i) {
        if (dif & (1 << i))
            x = d[x][i];
    }

    return ch[x];
}
#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...