제출 #1131754

#제출 시각아이디문제언어결과실행 시간메모리
1131754t9unkubj크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++20
34 / 100
1105 ms327680 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;
    vc<Node*>nxt;
    vc<vc<Node*>>come_jump;
    vc<vc<int>>come_idx;
    vc<Node*>jump;
    Node():jump(),nxt(),come_jump(),come_idx(),in(){}
};
void make(Node*x){
    for(int i=1;;i++){
        auto J=x->jump[i-1];
        
        if(J->jump.size()<=i-1)break;

        x->jump.push_back(J->jump[i-1]);
    }
}
void make2(Node*x,int idx){
    for(int i=1;;i++){
        auto I=x->come_idx[idx][i-1];
        auto J=x->come_jump[idx][i-1];
        if(J->come_jump[I].size()<=i-1)break;
        x->come_jump[idx].push_back(J->come_jump[I][i-1]);
        x->come_idx[idx].push_back(J->come_idx[I][i-1]);
    }
}
char last;
Node*now;
void Init() {
    now=new Node();
    now->sz=0;
    now->come_jump.push_back({});
    now->come_idx.push_back({});
}

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].resize(1);
    nxt->come_jump[0].resize(1);
    nxt->jump.resize(1);
    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({});
    tmp->come_idx.back().resize(1);
    tmp->come_jump.back().resize(1);

    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 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...