Submission #200137

#TimeUsernameProblemLanguageResultExecution timeMemory
200137johuthaGame (IOI13_game)C++14
0 / 100
5 ms504 KiB
#include "game.h" #include <vector> #include <iostream> #include <cassert> #include <memory> #include <random> #define int long long #define seed 4134 using namespace std; int gcd(int a, int b) { if (a > b) swap(a, b); if (a == 0) return b; return gcd(b % a, a); } mt19937 rng(seed); uniform_int_distribution<int> uni(0, 1e12); struct node; using node_ptr = shared_ptr<node>; struct node { node_ptr l, r; int x; int pos, lp, rp; int v; int cv; void recompute() { cv = v; lp = pos; rp = pos; if (l) { cv = gcd(cv, l->cv); lp = l->lp; } if (r) { cv = gcd(cv, r->cv); rp = r->rp; } } node(int k, int iv) : pos(k), v(iv) { x = uni(rng); recompute(); } static node_ptr merge(node_ptr l, node_ptr r) { if (!l) return r; if (!r) return l; if (l->x > r->x) { l->r = merge(move(l->r), move(r)); l->recompute(); return l; } else { r->l = merge(move(l), move(r->l)); r->recompute(); return r; } } static pair<node_ptr, node_ptr> split(node_ptr rt, int pos) { if (!rt) return {}; if (pos <= rt->pos) { node_ptr l; tie(l, rt->l) = split(move(rt->l), pos); if (l) l->recompute(); if (rt) rt->recompute(); return {move(l), move(rt)}; } else { node_ptr r; tie(rt->r, r) = split(move(rt->r), pos); if (rt) rt->recompute(); if (r) r->recompute(); return {move(rt), move(r)}; } } bool update(int k, int iv) { if (k == pos) { v = iv; recompute(); return true; } if (l && k < pos) return l->update(k, iv); if (r && k > pos) return r->update(k, iv); recompute(); return false; } static node_ptr insert(node_ptr rt, int k, int v) { node_ptr l, r, np; tie(l, r) = split(move(rt), k); np = make_shared<node>(k, v); l = merge(move(l), move(np)); r = merge(move(l), move(r)); return move(r); } int query(int ql, int qr) { if (ql <= lp && rp <= qr) return cv; if (rp < ql || qr < lp) return 0; int g = 0; if (ql <= pos && pos <= qr) g = v; if (l) g = gcd(g, l->query(ql, qr)); if (r) g = gcd(g, r->query(ql, qr)); return g; } void print(int in) { if (l) l->print(in + 1); for (int i = 0; i < in; i++) cout << " "; cout << pos << " " << lp << " " << rp << " " << v << " " << cv << "\n"; if (r) r->print(in + 1); } }; vector<node_ptr> sts; int r, c; void init(signed R, signed C) { r = R; c = C; sts.resize(R); } void update(signed P, signed Q, int K) { if ((!sts[P]) || (!(sts[P]->update(Q, K)))) { sts[P] = node::insert(move(sts[P]), Q, K); } } int calculate(signed P, signed Q, signed U, signed V) { return 0; // cout << "\n"; if (U < P) swap(U, P); if (V < Q) swap(Q, V); int ret = 0; for (int i = P; i <= U; i++) { if (sts[i]) ret = gcd(ret, sts[i]->query(Q, V)); // cout << i << " " << sts[i].query(Q, V, 0, c - 1, 0) << "\n"; } return ret; }

Compilation message (stderr)

grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
#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...