제출 #988500

#제출 시각아이디문제언어결과실행 시간메모리
988500huutuanCrayfish scrivener (IOI12_scrivener)C++14
100 / 100
358 ms129184 KiB

#include <bits/stdc++.h>

using namespace std;

const int N=1e6+10, LG=20;
int dep[N], up[LG][N], node[N];
char a[N];
vector<int> g[N];
int cur, cnt;

void Init() {
   cur=0, cnt=0;
}

void TypeLetter(char L) {
   a[++cnt]=L;
   g[cur].push_back(cnt);
   dep[cnt]=dep[cur]+1;
   up[0][cnt]=cur;
   for (int k=1; k<LG; ++k) up[k][cnt]=up[k-1][up[k-1][cnt]];
   cur=cnt;
   node[cnt]=cur;
}

void UndoCommands(int U) {
   ++cnt;
   cur=node[cnt-U-1];
   node[cnt]=cur;
}

char GetLetter(int P) {
   int d=dep[cur]-P-1;
   int u=cur;
   for (int k=0; k<LG; ++k) if (d>>k&1) u=up[k][u];
   return a[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...