이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
ostream& operator<<(ostream &out, string str) {
for(char c : str) out << c;
return out;
}
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
return out << "(" << p.ST << ", " << p.ND << ")";
}
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
out << "{";
for(auto it = a.begin(); it != a.end(); it = next(it))
out << (it != a.begin() ? ", " : "") << *it;
return out << "}";
}
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
cerr << a << ", ";
dump(x...);
}
#ifdef DEBUG
# define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
# define debug(...) false
#endif
template<class T> int size(T && a) { return (int) a.size(); }
using LL = long long;
using PII = pair<int, int>;
vector<vector<int>> jump;
vector<char> label;
vector<int> dep;
int get_ptr(int v, int q) {
if(q < size(jump[v]))
return jump[v][q];
return -1;
}
int add_vertex(char c, int p) {
label.emplace_back(c);
if(p != -1) dep.emplace_back(dep[p] + 1);
else dep.emplace_back(-1);
jump.emplace_back();
auto &j = jump.back();
while(p != -1) {
j.emplace_back(p);
p = get_ptr(p, size(j) - 1);
}
return size(label) - 1;
}
vector<int> pos;
void Init() {
pos.emplace_back(add_vertex(0, -1));
}
void TypeLetter(char L) {
int last = pos.back();
pos.emplace_back(add_vertex(L, last));
}
void UndoCommands(int U) {
int s = size(pos) - 1;
pos.emplace_back(pos[s - U]);
}
char GetLetter(int P) {
int q = 0, v = pos.back();
int k = dep[v] - P;
while(k) {
if(k % 2)
v = get_ptr(v, q);
k /= 2, q++;
}
return label[v];
}
# | 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... |