제출 #202086

#제출 시각아이디문제언어결과실행 시간메모리
202086DavidDamianCrayfish scrivener (IOI12_scrivener)C++11
100 / 100
516 ms65784 KiB
#include<bits/stdc++.h>
using namespace std;
///Tree
///Ancestor to travel in O(log n)
///Persistent Array
///Determine the letter in position P
///You can add new letters or go back in time
int node[1000006];
int NEXT_FREE_INDEX=1;
int n=1;
int lv[1000006];
char letter[1000006];
int ancestor[21][1000006];
int len;
int cont=0;
void Init() {
    len=-1;
    lv[0]=-1;
}
void TypeLetter(char L) {
    int u=NEXT_FREE_INDEX++; //Last created node
    node[n]=u;
    lv[u]=lv[ node[n-1] ]+1;
    letter[u]=L;
    ancestor[0][u]=node[n-1];
    for(int i=1;i<=20;i++){ //We set the ancestors of the new node
        ancestor[i][u]=ancestor[i-1][ ancestor[i-1][u] ];
    }
    n++;
}
void UndoCommands(int U) { //The actual node changes to a past one
    node[n]=node[n-U-1];
    n++;
}
char GetLetter(int P) {
    int u=node[n-1];
    int d=lv[u]-P;
    for(int i=20;i>=0;i--){ //We travel the path to the root in jumps of 2^i
        if(d & (1<<i)){
            u=ancestor[i][u];
        }
    }
    return letter[u];
}
#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...