이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
char nodes[1000100]; int sz[1000100];
int lift[1000100][21];
int numVersions = 0;
int insert(int l, char c){
int ver = numVersions++;
nodes[ver] = c;
sz[ver] = sz[l]+1;
//cerr<<getsz(l) << " " << l->lift.size() << endl;
int i = 0;
while(true){
//cout<<getsz(l)<<endl;
lift[ver][i] = l;
//cout<<nl->lift.size()<<endl;
if(lift[l][i] == -1) return ver;
l = lift[l][i++];
}
}
char getletter(int l, int i){
//cerr<<getsz(l) << " " << l->lift.size() << endl;
FOR(k, 0, 21) if(i & (1<<k)) l = lift[l][k];
return nodes[l];
}
void Init() {
sz[0] = nodes[0] = 0;
numVersions = 1;
FOR(i, 0, 1000100) FOR(j, 0, 21) lift[i][j] = -1;
}
void TypeLetter(char L) {
//for(auto l : v) cout << getsz(l) << " " << (l ? to_string(l->lift.size()) :"") << endl;
insert(numVersions-1, L);
}
void UndoCommands(int U) {
int o = numVersions - 1 - U, n = numVersions++;
nodes[n] = nodes[o];
sz[n] = sz[o];
FOR(i, 0, 21) lift[n][i] = lift[o][i];
}
char GetLetter(int P) {
int v = numVersions - 1;
return getletter(v, sz[v]-1 - P);
}
# | 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... |