This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include "game.h"
#include<bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) (int)a.size()
#define s second
#define f first
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 2001;
int n, m;
long long gcd2(long long X, long long Y) {
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
vector<vector<ll>> t;
void upd1(bool is, int v, int p, ll vl, int u = 1, int tl = 0, int tr = m - 1) {
if (tl == tr) {
if (is) t[v][u] = vl;
else t[v][u] = gcd2(t[v * 2][u], t[v * 2 + 1][u]);
return;
}
int md = (tl + tr) / 2;
if (p <= md) upd1(is, v, p, vl, u * 2, tl, md);
else upd1(is, v, p, vl, u * 2 + 1, md + 1, tr);
t[v][u] = gcd2(t[v][u * 2], t[v][u * 2 + 1]);
}
void upd(int p1, int p2, ll vl, int u = 1, int tl = 0, int tr = n - 1) {
if (tl == tr) {
upd1(1, u, p2, vl);
return;
}
int md = (tl + tr) / 2;
if (p1 <= md) upd(p1, p2, vl, u * 2, tl, md);
else upd(p1, p2, vl, u * 2 + 1, md + 1, tr);
upd1(0, u, p2, vl);
}
ll get1(int v, int l, int r, int u = 1, int tl = 0, int tr = m - 1) {
if (tl > r || tr < l) return 0;
if (tl >= l && tr <= r) return t[v][u];
int md = (tl + tr) / 2;
return gcd2(get1(v, l, r, u * 2, tl, md), get1(v, l, r, u * 2 + 1, md + 1, tr));
}
ll get(int l1, int r1, int l2, int r2, int u = 1, int tl = 0, int tr = n - 1) {
if (tl > r1 || tr < l1) return 0;
if (tl >= l1 && tr <= r1) return get1(u, l2, r2);
int md = (tl + tr) / 2;
return gcd2(get(l1, r1, l2, r2, u * 2, tl, md), get(l1, r1, l2, r2, u * 2 + 1, md + 1, tr));
}
void init(int R, int C) {
n = R, m = C;
t.resize(4 * n);
for (int i = 0; i < 4 * n; i++) t[i].resize(4 * m);
}
void update(int P, int Q, ll K) {
upd(P, Q, K);
}
ll calculate(int P, int Q, int U, int V) {
return get(P, U, Q, V);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |