제출 #1131719

#제출 시각아이디문제언어결과실행 시간메모리
1131719t9unkubj크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++20
34 / 100
1096 ms30776 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=20; struct Node{ int sz; char in; vc<Node*>nxt; vc<Node*>come; //K回目にここに来た時に何番目の操作でたどり着いたか vc<int>come_op; array<Node*,LOG>jump; Node():jump(),nxt(),come_op(),come(),in(){} }; void make(Node*x){ REP(i,1,LOG){ auto J=x->jump[i-1]; x->jump[i]=J->jump[i-1]; } } char last; Node*now; void Init() { now=new Node(); now->sz=0; rep(i,LOG){ now->jump[i]=now; } now->come.push_back(nullptr); } void TypeLetter(char L) { auto nxt=new Node(); nxt->in=L; nxt->sz=now->sz+1; nxt->come_op.push_back(now->nxt.size()); nxt->come.push_back(now); nxt->jump[0]=now; make(nxt); now->nxt.push_back(nxt); now=nxt; } void UndoCommands(int U) { auto tmp=now; int nxt_idx=tmp->come.size()-1; rep(i,U){ auto mada=tmp->come_op[nxt_idx]; tmp=tmp->come[nxt_idx]; nxt_idx=mada; } tmp->come.push_back(now); tmp->come_op.push_back(now->nxt.size()); now->nxt.push_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...