Submission #641518

#TimeUsernameProblemLanguageResultExecution timeMemory
641518ymmCrayfish scrivener (IOI12_scrivener)C++17
34 / 100
1078 ms244936 KiB
#include <bits/stdc++.h> #define Loop(x,l,r) for (ll x = (l); x < (r); ++x) #define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x) typedef long long ll; typedef std::pair<int, int> pii; typedef std::pair<ll , ll > pll; using namespace std; const int lg = 16; struct node { node *par_com[lg]; node *par_let[lg]; int len; char let; } *cur; node pool[250'000'000/sizeof(node)]; int next_node = 0; node *new_node() { return pool + (next_node++); } void Init() { cur = new_node(); Loop (i,0,lg) { cur->par_com[i] = cur; cur->par_let[i] = cur; } cur->len = 0; cur->let = 0; } void TypeLetter(char L) { node *next = new_node(); next->par_com[0] = cur; next->par_let[0] = cur; Loop (i,0,lg-1) { next->par_com[i+1] = next->par_com[i]->par_com[i]; next->par_let[i+1] = next->par_let[i]->par_let[i]; } next->len = next->par_let[0]->len + 1; next->let = L; cur = next; } void UndoCommands(int U) { node *sib = cur; while (U >= (1 << lg)) { sib = sib->par_com[lg-1]; U -= 1 << (lg-1); } Loop (i,0,lg) { if (U & (1<<i)) sib = sib->par_com[i]; } node *next = new_node(); next->par_com[0] = cur; next->par_let[0] = sib->par_let[0]; Loop (i,0,lg-1) { next->par_com[i+1] = next->par_com[i]->par_com[i]; next->par_let[i+1] = next->par_let[i]->par_let[i]; } next->len = next->par_let[0]->len + 1; next->let = sib->let; cur = next; } char GetLetter(int P) { P = cur->len - 1 - P; node *ans = cur; while (P >= (1 << lg)) { ans = ans->par_let[lg-1]; P -= 1 << (lg-1); } Loop (i,0,lg) { if (P & (1<<i)) ans = ans->par_let[i]; } return ans->let; }
#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...