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;
#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 = 2e3 + 5;
int n, m, lg[N], pw[7];
ll vl[N][N], up[N][N][7];
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;
}
ll get(int R, int l, int r) {
int k = lg[r - l + 1], p = l;
ll res = 0;
while (true) {
res = gcd2(res, up[R][p][k]);
p += pw[k];
if (p > r) break;
p = min(p, r - pw[k] + 1);
}
return res;
}
void bld(int R) {
for (int k = 0; k < 7; k++) {
for (int i = 0; i < m - pw[k] + 1; i++) {
if (k) {
int v = pw[k - 1];
up[R][i][k] = gcd2(up[R][i][k - 1], up[R][i + v][k - 1]);
up[R][i][k] = gcd2(up[R][i][k], up[R][i + 2 * v][k - 1]);
}else up[R][i][k] = vl[R][i];
}
}
}
void init(int R, int C) {
n = R, m = C;
lg[0] = -1;
pw[0] = 1;
for (int i = 1; i < 7; i++) pw[i] = pw[i - 1] * 3;
for (int i = 1; i <= m; i++) {
lg[i] = lg[i / 3] + 1;
}
cout << '\n';
}
void update(int P, int Q, ll K) {
vl[P][Q] = K;
bld(P);
}
ll calculate(int P, int Q, int U, int V) {
ll ans = 0;
for (int i = P; i <= U; i++) {
ans = gcd2(ans, get(i, Q, V));
}
return ans;
}
# | 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... |