이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |