이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "game.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
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;
}
const int MAX_N = 2005;
struct Seg1 {
int n;
vi seg;
Seg1() {}
Seg1(int m) {
for (n = 1; n < m; n <<= 1);
seg.resize(2 * n);
}
void update(int i, ll x) {
seg[i += n] = x;
for (i >>= 1; i; i >>= 1) {
seg[i] = gcd2(seg[i << 1], seg[i << 1 | 1]);
}
}
ll query(int l, int r) {
ll x = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) x = gcd2(x, seg[l++]);
if (r & 1) x = gcd2(x, seg[--r]);
}
return x;
}
};
struct Seg2 {
int n, m;
vector<Seg1> seg;
Seg2 () {}
Seg2 (int n1, int m1) {
for (n = 1; n < n1; n <<= 1);
seg.resize(2 * n, Seg1(m1));
m = seg[0].n;
}
void update(int i, int j, ll x) {
seg[i += n].update(j, x);
for (i >>= 1; i; i >>= 1) {
x = gcd2(seg[i << 1].seg[m + j], seg[i << 1 | 1].seg[m + j]);
seg[i].update(j, x);
}
}
ll query(int x1, int y1, int x2, int y2) {
ll x = 0;
for (x1 += n, x2 += n; x1 < x2; x1 >>= 1, x2 >>= 1) {
if (x1 & 1) x = gcd2(x, seg[x1++].query(y1, y2));
if (x2 & 1) x = gcd2(x, seg[--x2].query(y1, y2));
}
return x;
}
};
Seg2 mat;
int n, m;
void init(int R, int C) {
n = R, m = C;
mat = Seg2(n, m);
}
void update(int p, int q, long long k) {
mat.update(p, q, k);
}
long long calculate(int p, int q, int u, int v) {
return mat.query(p, q, u + 1, v + 1);
}
# | 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... |