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];
ll vl[N][N], up[N][N][11];
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];
return gcd2(up[R][l][k], up[R][r - (1 << k) + 1][k]);
}
void bld(int R) {
for (int k = 0; k < 11; k++) {
for (int i = 0; i < m - (1 << k) + 1; i++) {
if (k) {
up[R][i][k] = gcd2(up[R][i][k - 1], up[R][i + (1 << (k - 1))][k - 1]);
}else up[R][i][k] = vl[R][i];
}
}
}
void init(int R, int C) {
n = R, m = C;
lg[0] = -1;
for (int i = 1; i <= m; i++) lg[i] = lg[i / 2] + 1;
}
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... |