이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int lg = 15;
struct node {
node *par_com[lg];
node *par_let[lg];
int len;
char let;
} *cur;
void Init()
{
cur = new node;
Loop (i,0,lg) {
cur->par_com[i] = cur;
cur->par_let[i] = cur;
}
cur->len = 0;
cur->let = 0;
}
void TypeLetter(char L)
{
node *next = new node;
next->par_com[0] = cur;
next->par_let[0] = cur;
Loop (i,0,lg-1) {
next->par_com[i+1] = next->par_com[i]->par_com[i];
next->par_let[i+1] = next->par_let[i]->par_let[i];
}
next->len = next->par_let[0]->len + 1;
next->let = L;
cur = next;
}
void UndoCommands(int U)
{
node *sib = cur;
while (U >= (1 << lg)) {
sib = sib->par_com[lg-1];
U -= 1 << (lg-1);
}
Loop (i,0,lg) {
if (U & (1<<i))
sib = sib->par_com[i];
}
node *next = new node;
next->par_com[0] = cur;
next->par_let[0] = sib->par_let[0];
Loop (i,0,lg-1) {
next->par_com[i+1] = next->par_com[i]->par_com[i];
next->par_let[i+1] = next->par_let[i]->par_let[i];
}
next->len = next->par_let[0]->len + 1;
next->let = sib->let;
cur = next;
}
char GetLetter(int P)
{
P = cur->len - 1 - P;
node *ans = cur;
while (P >= (1 << lg)) {
ans = ans->par_let[lg-1];
P -= 1 << (lg-1);
}
Loop (i,0,lg) {
if (P & (1<<i))
ans = ans->par_let[i];
}
return ans->let;
}
# | 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... |