제출 #738862

#제출 시각아이디문제언어결과실행 시간메모리
738862Muaath_5게임 (IOI13_game)C++17
0 / 100
1 ms340 KiB
#include "game.h" #include <bits/stdc++.h> #define ll long long using namespace std; const int N = 1e9 + 1; const ll OUT = 0; ll merge(ll t1, ll t2) { return gcd(t1, t2); } struct ynode { ll val = OUT; ynode* left = nullptr, * right = nullptr; inline void upd() { ll m1 = OUT, m2 = OUT; if (left) m1 = left->val; if (right) m2 = right->val; val = merge(m1, m2); } }; struct xnode { xnode* left = nullptr, * right = nullptr; ynode* yy = new ynode(); }; ll query_y(int qy1, 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(int qx1, int qy1, int qx2, 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(int qy, 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); } node->upd(); } void update_x(int qx, int qy, ll val, xnode* node, int l = 0, int r = N - 1) { if (l != r) { 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, ll k) { update_x(x, y, k, root); } ll 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...