This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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;
}
int nx, ny;
vector<vector<ll>> dat;
void upd(int x, int y, ll to) {
int kx = x + nx, ky = y + ny;
dat[kx][ky] = to;
while (kx > 0) {
if (kx < x + nx) {
dat[kx][ky] = gcd2(dat[kx << 1][ky], dat[kx << 1 | 1][ky]);
}
int k = ky;
k >>= 1;
while (k > 0) {
dat[kx][k] = gcd2(dat[kx][k << 1], dat[kx][k << 1 | 1]);
k >>= 1;
}
kx >>= 1;
}
}
ll getx(int x1, int y1, int x2, int y2, int ky, int k, int l, int r) {
if (x2 <= l || r <= x1) {
return 0;
}
if (x1 <= l && r <= x2) {
return dat[k][ky];
}
ll vl = getx(x1, y1, x2, y2, ky, k << 1, l, (l + r) / 2);
ll vr = getx(x1, y1, x2, y2, ky, k << 1 | 1, (l + r) / 2, r);
return gcd2(vl, vr);
}
ll gety(int x1, int y1, int x2, int y2, int k, int l, int r) {
if (y2 <= l || r <= y1) {
return 0;
}
if (y1 <= l && r <= y2) {
return getx(x1, y1, x2, y2, k, 1, 0, ny);
}
ll vl = gety(x1, y1, x2, y2, k << 1, l, (l + r) / 2);
ll vr = gety(x1, y1, x2, y2, k << 1 | 1, (l + r) / 2, r);
return gcd2(vl, vr);
}
void init(int R, int C) {
++R;
++C;
nx = 1;
while (nx < R) {
nx <<= 1;
}
ny = 1;
while (ny < C) {
ny <<= 1;
}
dat.resize(2 * nx);
for (int i = 0; i < 2 * nx; i++) {
dat[i].resize(2 * ny);
}
}
void update(int P, int Q, long long K) { upd(P, Q, K); }
long long calculate(int P, int Q, int U, int V) {
return gety(P, Q, U + 1, V + 1, 1, 0, nx);
}
Compilation message (stderr)
grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
int res;
^~~
# | 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... |