Submission #240811

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
2408112020-06-21 08:32:12wleung_bvgSynchronization (JOI13_synchronization)C++17
100 / 100
199 ms18284 KiB
#include <bits/stdc++.h>
using namespace std;
template<class C>constexpr int sz(const C&c){return int(c.size());}
using ll=long long;constexpr const char nl='\n',sp=' ';
template <class _Node, class Container = deque<_Node>> struct Splay {
using Node = _Node; Container TR; deque<Node*> deleted;
static_assert(Node::HAS_PAR, "Splay Node must have parent pointer");
template <class T> Node *makeNode(const T &v) {
if (deleted.empty()) { TR.emplace_back(v); return &TR.back(); }
Node *x = deleted.back(); deleted.pop_back();
*x = typename Container::value_type(v); return x;
}
bool isRoot(Node *x) { return !x->p || (x != x->p->l && x != x->p->r); }
void connect(Node *x, Node *p, bool hasCh, bool isL) {
if (x) x->p = p;
if (hasCh) (isL ? p->l : p->r) = x;
}
void rotate(Node *x) {
Node *p = x->p, *g = p->p; bool isRootP = isRoot(p), isL = x == p->l;
connect(isL ? x->r : x->l, p, true, isL); connect(p, x, true, !isL);
connect(x, g, !isRootP, !isRootP && p == g->l); p->update();
}
void splay(Node *x) {
while (!isRoot(x)) {
Node *p = x->p, *g = p->p; if (!isRoot(p)) g->propagate();
p->propagate(); x->propagate();
if (!isRoot(p)) rotate((x == p->l) == (p == g->l) ? p : x);
rotate(x);
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#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...