Submission #937938

#TimeUsernameProblemLanguageResultExecution timeMemory
937938Muaath_5Game (IOI13_game)C++17
63 / 100
1699 ms256000 KiB
#include "game.h" #define ll long long #define OUT 0ll ll gcd2(ll x, ll y) { if (y == 0) return x; return gcd2(y, x % y); } #define merge gcd2 using namespace std; const int N = 1e9 + 1; struct ynode { ll val = OUT; ynode* left = nullptr, * right = nullptr; }; struct xnode { xnode* left = nullptr, * right = nullptr; ynode* yy = nullptr; }; ll query_y(const int& qy1, const int& qy2, ynode* node, int l = 0, int r = N - 1) { if (node == nullptr || r < qy1 || qy2 < l) return OUT; if (qy1 <= l && r <= qy2) return node->val; const int mid = (l + r) / 2; return merge( query_y(qy1, qy2, node->left, l, mid), query_y(qy1, qy2, node->right, mid + 1, r) ); } ll query_x(const int& qx1, const int& qy1, const int& qx2, const int& qy2, xnode* node, int l = 0, int r = N - 1) { if (node == nullptr || r < qx1 || qx2 < l) return OUT; if (qx1 <= l && r <= qx2) return query_y(qy1, qy2, node->yy); const int mid = (l + r) / 2; return merge( query_x(qx1, qy1, qx2, qy2, node->left, l, mid), query_x(qx1, qy1, qx2, qy2, node->right, mid + 1, r) ); } void update_y(const int& qy, const ll& val, ynode* node, int l = 0, int r = N - 1) { if (l == r) { node->val = val; return; } const int mid = (l + r) / 2; if (qy <= mid) { if (!node->left) node->left = new ynode(); update_y(qy, val, node->left, l, mid); } else { if (!node->right) node->right = new ynode(); update_y(qy, val, node->right, mid + 1, r); } ll m1 = OUT, m2 = OUT; if (node->left) m1 = node->left->val; if (node->right) m2 = node->right->val; node->val = merge(m1, m2); } void update_x(const int& qx, const int& qy, const ll& val, xnode* node, int l = 0, int r = N - 1) { if (!node->yy) node->yy = new ynode(); if (l == r) { update_y(qy, val, node->yy); return; } const int mid = (l + r) / 2; if (qx <= mid) { if (!node->left) node->left = new xnode(); update_x(qx, qy, val, node->left, l, mid); } else { if (!node->right) node->right = new xnode(); update_x(qx, qy, val, node->right, mid + 1, r); } update_y(qy, merge( (node->left && node->left->yy ? query_y(qy, qy, node->left->yy) : OUT), (node->right && node->right->yy ? query_y(qy, qy, node->right->yy) : OUT) ), node->yy); } xnode* root; void init(int R, int C) { root = new xnode(); } void update(int x, int y, long long k) { update_x(x, y, k, root); } long long calculate(int x1, int y1, int x2, int y2) { return query_x(x1, y1, x2, y2, root); }
#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...