제출 #1131776

#제출 시각아이디문제언어결과실행 시간메모리
1131776t9unkubj크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++20
5 / 100
273 ms105616 KiB
#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;
}
double pass_time=0;
const int LOG=19;
struct Node{
    int sz;
    char in;
    array<Node*,LOG>jump;
    Node():jump(),in(){}

};
void make(Node*x){
    REP(i,1,LOG){
        auto J=x->jump[i-1];
        x->jump[i]=J->jump[i-1];
    }
}

Node*node[(int)1e6+10];
Node*now;
int now_idx=-1;
void Init() {
    node[++now_idx]=new Node();
    now=node[now_idx];
    now->sz=0;
    rep(i,LOG)now->jump[i]=now;
}

void TypeLetter(char L) {
    node[++now_idx]=new Node();
    auto nxt=node[now_idx];
    nxt->in=L;
    nxt->sz=now->sz+1;
    
    nxt->jump[0]=now;
    make(nxt);
    now=nxt;
}

void UndoCommands(int U) {
    auto R=node[now_idx-U];
    node[++now_idx]=node[now_idx];
    now=node[now_idx];
}

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...