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>
using namespace std;
const int MXN = 1 << 20;
const int COEFF = 8;
char mem[COEFF*MXN];
int llink[COEFF*MXN];
int rlink[COEFF*MXN];
int root;
int nodesz;
vector<int> rootlist;
vector<int> lens;
inline int newnode(int o = -1){
int c = ++nodesz;
if(o != -1){
llink[c] = llink[o];
rlink[c] = rlink[o];
mem[c] = mem[o];
}
return c;
}
inline int build(int l, int r){
int c = newnode();
if(l == r) return c;
int k = (l+r)/2;
llink[c] = build(l,k);
rlink[c] = build(k+1,r);
return c;
}
inline int update(int o, int idx, char upd, int lb, int rb){
int c = newnode(o);
if(lb == rb){
mem[c] = upd;
return c;
}
int k = (lb + rb)/2;
if(idx <= k){
llink[c] = update(llink[c], idx, upd, lb, k);
}else{
rlink[c] = update(rlink[c], idx, upd, k+1, rb);
}
return c;
}
inline char query(int c, int idx, int lb, int rb){
if(lb == rb) return mem[c];
int k = (lb + rb)/2;
if(idx <= k) return query(llink[c], idx, lb, k);
else return query(rlink[c], idx, k+1, rb);
}
void Init() {
root = build(0, MXN-1);
rootlist.push_back(root);
lens.push_back(0);
}
void TypeLetter(char L) {
int l = lens.back();
int o = rootlist.back();
int c = update(o, l, L, 0, MXN-1);
rootlist.push_back(c);
lens.push_back(l+1);
}
void UndoCommands(int U) {
int vn = rootlist.size() - 1 - U;
lens.push_back(lens[vn]);
rootlist.push_back(rootlist[vn]);
}
char GetLetter(int P) {
return query(rootlist.back(), P, 0, MXN-1);
}
# | 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... |