이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
struct node {
char c;
array<node*, 22> par;
int len;
vector<array<pair<node*, int>, 22>> undo;
};
typedef node* pnode;
pnode root;
pnode cur;
void Init() {
root = new node();
root->len = -1;
cur = root;
}
void TypeLetter(char L) {
pnode tmp = new node();
tmp->par[0] = cur;
for (int i = 1; i < 22; i++) {
if(tmp->par[i - 1] == NULL) break;
tmp->par[i] = tmp->par[i - 1]->par[i - 1];
}
tmp->undo.push_back({});
tmp->undo.back()[0] = {cur, cur->undo.size() - 1};
for (int i = 1; i < 22; i++) tmp->undo.back()[i].second = -1;
for (int i = 1; i < 22; i++) {
if(tmp->undo.back()[i - 1].second == -1) break;
int b = tmp->undo.back()[i - 1].second;
tmp->undo.back()[i] = tmp->undo.back()[i - 1].first->undo[b][i - 1];
}
tmp->c = L;
tmp->len = cur->len + 1;
cur = tmp;
}
void UndoCommands(int U) {
pnode tmp = cur;
int b = tmp->undo.size() - 1;
for (int i = 0; i < 22; i++) {
if(U & (1 << i)){
int tb = tmp->undo[b][i].second;
tmp = tmp->undo[b][i].first;
b = tb;
}
}
tmp->undo.push_back({});
tmp->undo.back()[0] = {cur, cur->undo.size() - 1};
for (int i = 1; i < 22; i++) tmp->undo.back()[i].second = -1;
for (int i = 1; i < 22; i++) {
if(tmp->undo.back()[i - 1].second == -1) break;
int b = tmp->undo.back()[i - 1].second;
tmp->undo.back()[i] = tmp->undo.back()[i - 1].first->undo[b][i - 1];
}
cur = tmp;
}
char GetLetter(int P) {
pnode tmp = cur;
int x = tmp->len - P;
for (int i = 0; i < 22; i++) {
if(x & (1 << i)){
tmp = tmp->par[i];
}
}
return tmp->c;
}
# | 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... |