# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
237457 | nicolaalexandra | Crayfish scrivener (IOI12_scrivener) | C++14 | 645 ms | 97400 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DIM 1000010
using namespace std;
int v[DIM],tip[DIM],fth[DIM],level[DIM],dp[DIM][20];
int nr_nodes,k;
void Init(){}
void TypeLetter (char L) {
int nod = v[k];
int vecin = ++nr_nodes;
v[++k] = nr_nodes;
//L[nod].push_back(vecin);
//L[vecin].push_back(nod);
tip[vecin] = L - 'a';
/// fth[i] - primul nod (in sus) care e litera
if (tip[nod] == -1) /// e nod de undo
fth[vecin] = fth[nod];
else fth[vecin] = nod;
level[vecin] = 1 + level[fth[vecin]];
/// stramosi 2^k
dp[vecin][0] = fth[vecin];
for (int i=1;i<=20;i++)
dp[vecin][i] = dp[dp[vecin][i-1]][i-1];
}
void UndoCommands(int U) {
int nod = v[k-U];
int vecin = ++nr_nodes;
v[++k] = nr_nodes;
tip[vecin] = -1;
if (tip[nod] == -1)
fth[vecin] = fth[nod];
else fth[vecin] = nod;
}
char GetLetter(int P) {
int nod = v[k];
if (tip[nod] == -1)
nod = fth[nod];
int val = level[nod] - P - 1;
for (int i=20;i>=0;i--){
if ((1<<i) <= val){
val -= (1<<i);
nod = dp[nod][i];
}
}
return (char)(tip[nod] + 'a');
}
Compilation message (stderr)
# | 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... |