Submission #581725

#TimeUsernameProblemLanguageResultExecution timeMemory
581725ggohGame (IOI13_game)C++14
0 / 100
1 ms340 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; int R, C, N, ch, P, Q, U, V; int px, qx, py, qy; int xco, yco; long long K; struct Y { Y *left, *right; long long val; Y() { left = right = NULL; val = 0ll; } }; struct X { X *left, *right; Y *ynode; X() { left = right = NULL; ynode = NULL; } } * inix; long long gcd2(long long xx, long long yy) { if (yy == 0) return xx; return gcd2(yy, xx % yy); } void yup(Y *y, int s, int e, long long v) { int m = (s + e) >> 1; if (s == e) { y->val = v; return; } if (m >= yco) { if (!y->left) { y->left = new Y(); } yup(y->left, s, m, v); } else { if (!y->right) { y->right = new Y(); } yup(y->right, m + 1, e, v); } long long l = 0, r = 0; if (y->left) l = y->left->val; if (y->right) r = y->right->val; y->val = gcd2(l, r); } long long yans(Y *y, int s, int e) { int m = (s + e) >> 1; if ((!y) || s > qy || e < py) return 0ll; if (py <= s && e <= qy) return y->val; long long l = 0, r = 0; if (y->left) l = yans(y->left, s, m); if (y->right) r = yans(y->right, m + 1, e); return gcd2(l, r); } void xup(X *x, int s, int e, long long v) { int m = (s + e) >> 1; if (!x->ynode) x->ynode = new Y(); if (s != e) { if (m >= xco) { if (!x->left) { x->left = new X(); } xup(x->left, s, m, v); } else { if (!x->right) { x->right = new X(); } xup(x->right, m + 1, e, v); } } long long realv; if (s == e) realv = v; else { realv = gcd2(x->left ? yans(x->left->ynode, yco, yco) : 0, x->right ? yans(x->right->ynode, yco, yco) : 0); } yup(x->ynode, 0, C - 1, realv); } long long xans(X *x, int s, int e) { int m = (s + e) >> 1; if ((!x->ynode) || s > qx || e < px) return 0ll; if (px <= s && e <= qx) { return yans(x->ynode, 0, C - 1); } long long l = 0, r = 0; if (x->left) l = xans(x->left, s, m); if (x->right) r = xans(x->right, m + 1, e); return gcd2(l, r); } void init(int RR, int CC) { R = RR; C = CC; inix = new X(); } void update(int P, int Q, long long K) { xco = P; yco = Q; xup(inix, 0, R - 1, K); } long long calculate(int P, int Q, int U, int V) { px = P; qx = U; py = Q; qy = V; return xans(inix, 0, R - 1); }
#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...