#ifdef t9unkubj
#include"debug.cpp"
//#include"template_no_debug.h"
#else
#define dbg(...) 199958
#endif
#undef _GLIBCXX_DEBUG
#pragma GCC optimize("O3")
using namespace std;
#include<bits/stdc++.h>
using ll=long long;
using ull=unsigned long long;
template<class T>using vc=vector<T>;
template<class T>using vvc=vc<vc<T>>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++)
#define DREP(i,n,m) for(ll i=(n);i>=(m);i--)
#define drep(i,n) for(ll i=((n)-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
template<class T,class F>
bool chmin(T &x, F y){
if(x>y){
x=y;
return true;
}
return false;
}
template<class T, class F>
bool chmax(T &x, F y){
if(x<y){
x=y;
return true;
}
return false;
}
#define push_back emplace_back
double pass_time=0;
const int LOG=19;
struct Node{
int sz;
char in;
vc<Node*>nxt;
vc<array<Node*,LOG>>come_jump;
vc<array<int,LOG>>come_idx;
array<Node*,LOG>jump;
Node():jump(),nxt(),come_jump(),come_idx(),in(){}
};
void make(Node*x){
REP(i,1,LOG){
auto J=x->jump[i-1];
x->jump[i]=J->jump[i-1];
}
}
void make2(Node*x,int idx){
REP(i,1,LOG){
auto I=x->come_idx[idx][i-1];
auto J=x->come_jump[idx][i-1];
x->come_jump[idx][i]=J->come_jump[I][i-1];
x->come_idx[idx][i]=J->come_idx[I][i-1];
}
}
char last;
Node*now;
void Init() {
vc<int>v;
while(1){
v.push_back(0);
}
now=new Node();
now->sz=0;
now->come_jump.push_back();
now->come_idx.push_back();
rep(i,LOG){
now->jump[i]=now;
now->come_jump[0][i]=now;
now->come_idx[0][i]=0;
}
}
void TypeLetter(char L) {
auto nxt=new Node();
nxt->in=L;
nxt->sz=now->sz+1;
nxt->come_jump.push_back();
nxt->come_idx.push_back();
nxt->come_idx[0][0]=now->nxt.size();
nxt->come_jump[0][0]=now;
nxt->jump[0]=now;
now->nxt.push_back(nxt);
make(nxt);
make2(nxt,0);
now=nxt;
}
void UndoCommands(int U) {
auto tmp=now;
int nxt_idx=tmp->come_jump.size()-1;
int t=0;
while(U){
if(U&1){
auto mada=tmp->come_idx[nxt_idx][t];
tmp=tmp->come_jump[nxt_idx][t];
nxt_idx=mada;
}
t++;
U/=2;
}
tmp->come_jump.push_back();
tmp->come_idx.push_back();
int V=tmp->come_jump.size()-1;
tmp->come_jump[V][0]=now;
tmp->come_idx[V][0]=now->nxt.size();
make2(tmp,V);
now->nxt.emplace_back(tmp);
now=tmp;
}
char GetLetter(int P) {
++P;
auto NOW=now;
int t=0;
P=now->sz-P;
while(P){
if(P&1)NOW=NOW->jump[t];
t++;
P/=2;
}
return NOW->in;
}
namespace judge{
void run(){
Init();
int q;
cin>>q;
while(q--){
int t;
cin>>t;
if(t==1){
char L;
cin>>L;
TypeLetter(L);
}
if(t==2){
int U;
cin>>U;
UndoCommands(U);
}
if(t==3){
int P;
cin>>P;
cout<<GetLetter(P)<<endl;
}
}
}
};
//int main(){judge::run();}
/*
g++ env/scrivener.cpp -D t9unkubj
19
1 A
1 B
1 C
1 D
3 2
2 2
3 2
3 1
1 E
1 F
3 3
3 1
2 3
3 4
3 3
3 2
2 2
3 1
3 2
*/
/*
12
1 A
1 B
1 C
1 D
3 2 (ans==B)
2 2
3 2 (ans==B)
3 1 (ans==A)
1 E
1 F
3 3 (ans==E)
3 1 (ans==A)
2 3
3 4 (ans==D)
3 3 (ans==C)
3 2 (ans==B)
2 2
3 1 (ans==A)
3 2 (ans==B)
*/
# | 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... |