Submission #750963

#TimeUsernameProblemLanguageResultExecution timeMemory
750963alex_2008Game (IOI13_game)C++14
37 / 100
785 ms25860 KiB
#include "game.h" #include <vector> typedef long long ll; using namespace std; const int N = 11, M = 100100; ll tree[N][4 * M], a[110][110]; int H, W; ll __gcd(ll a, ll b) { while (a && b) { (a > b) ? a %= b : b %= a; } return a + b; } void update1(int R, int C, ll value, int v, int tl, int tr) { if (tl > C || tr < C) { return; } if (tl == tr) { tree[R][v] = value; return; } int tm = (tl + tr) / 2; update1(R, C, value, 2 * v, tl, tm); update1(R, C, value, 2 * v + 1, tm + 1, tr); tree[R][v] = __gcd(tree[R][2 * v], tree[R][2 * v + 1]); } ll GCD(int R, int v, int tl, int tr, int l, int r) { if (tl >= l && tr <= r) return tree[R][v]; if (tl > r || tr < l) return 0; int tm = (tl + tr) / 2; return __gcd(GCD(R, 2 * v, tl, tm, l, r), GCD(R, 2 * v + 1, tm + 1, tr, l, r)); } void init(int R, int C) { H = R; W = C; } void update(int R, int Q, ll K) { if (max(H, W) <= 100) { a[R][Q] = K; return; } update1(R, Q, K, 1, 0, W - 1); } ll calculate(int P, int Q, int U, int V) { if (max(H, W) <= 100) { ll u = 0; for (int i = P; i <= U; i++) { for (int j = Q; j <= V; j++) { u = __gcd(u, a[i][j]); } } return u; } ll u = 0; for (int i = P; i <= U; i++) { u = __gcd(u, GCD(i, 1, 0, W - 1, Q, V)); } return u; }
#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...