제출 #1131767

#제출 시각아이디문제언어결과실행 시간메모리
1131767t9unkubjCrayfish scrivener (IOI12_scrivener)C++20
34 / 100
896 ms298720 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<int>nxt; vc<array<int,LOG>>come_jump; vc<array<int,LOG>>come_idx; array<int,LOG>jump; Node():sz(),jump(),nxt(),come_jump(),come_idx(),in(){} }; vc<Node>node; void make(int x){ REP(i,1,LOG){ auto J=node[x].jump[i-1]; node[x].jump[i]=node[J].jump[i-1]; } } void make2(int x,int idx){ REP(i,1,LOG){ auto I=node[x].come_idx[idx][i-1]; auto J=node[x].come_jump[idx][i-1]; node[x].come_jump[idx][i]=node[J].come_jump[I][i-1]; node[x].come_idx[idx][i]=node[J].come_idx[I][i-1]; } } char last; int now; int T=0; int nw(){ node.emplace_back(); return T++; } void Init() { now=nw(); node[now].sz=0; node[now].come_jump.push_back({}); node[now].come_idx.push_back({}); rep(i,LOG){ node[now].jump[i]=now; node[now].come_jump[0][i]=now; node[now].come_idx[0][i]=0; } } void TypeLetter(char L) { int nxt=nw(); node[nxt].in=L; node[nxt].sz=node[now].sz+1; node[nxt].come_jump.push_back({}); node[nxt].come_idx.push_back({}); node[nxt].come_idx[0][0]=node[now].nxt.size(); node[nxt].come_jump[0][0]=now; node[nxt].jump[0]=now; node[now].nxt.push_back(nxt); make(nxt); make2(nxt,0); now=nxt; } void UndoCommands(int U) { auto tmp=now; int nxt_idx=node[tmp].come_jump.size()-1; int t=0; while(U){ if(U&1){ auto mada=node[tmp].come_idx[nxt_idx][t]; tmp=node[tmp].come_jump[nxt_idx][t]; nxt_idx=mada; } t++; U/=2; } node[tmp].come_jump.push_back({}); node[tmp].come_idx.push_back({}); int V=node[tmp].come_jump.size()-1; node[tmp].come_jump[V][0]=now; node[tmp].come_idx[V][0]=node[now].nxt.size(); make2(tmp,V); node[now].nxt.emplace_back(tmp); now=tmp; } char GetLetter(int P) { ++P; auto NOW=now; int t=0; P=node[now].sz-P; while(P){ if(P&1)NOW=node[NOW].jump[t]; t++; P/=2; } return node[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...