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 <bits/stdc++.h>
#include "game.h"
using namespace std;
int n, m;
//vector< vector<int> > seg;
struct seg1d {
int n;
vector<long long> a;
seg1d(int n): n(n) {
a.resize(n * 4);
}
inline void upd(int x, int l, int r, int id, long long val) {
if (l == r) {
a[x] = val;
return;
}
int m = (l + r) >> 1;
if (id <= m) upd(2 * x + 1, l, m, id, val);
else upd(2 * x + 2, m + 1, r, id, val);
a[x] = __gcd(a[2 * x + 1], a[2 * x + 2]);
}
inline void upd2(int x, int l, int r, int id, seg1d &L, seg1d &R) {
if (l == r) {
a[x] = __gcd(L.a[x], R.a[x]);
return;
}
int m = (l + r) >> 1;
if (id <= m) upd2(2 * x + 1, l, m, id, L, R);
else upd2(2 * x + 2, m + 1, r, id, L, R);
a[x] = __gcd(a[2 * x + 1], a[2 * x + 2]);
}
inline long long get(int x, int lx, int rx, int l, int r) {
if (l <= lx && rx <= r)
return a[x];
if (rx < l || r < lx)
return 0;
int m = (lx + rx) >> 1;
long long t1 = get(2 * x + 1, lx, m, l, r);
long long t2 = get(2 * x + 2, m + 1, rx, l, r);
return __gcd(t1, t2);
}
inline void upd(int id, long long val) {
upd(0, 1, n, id, val);
}
inline void upd2(int id, seg1d &a, seg1d &b) {
upd2(0, 1, n, id, a, b);
}
inline long long get(int l, int r) {
return get(0, 1, n, l, r);
}
};
struct seg2d {
vector<seg1d> a;
int n;
seg2d(int n, int m): n(n) {
a.resize(n * 4, seg1d(m));
}
seg2d() {}
void init(int n, int m) {
a.resize(n * 4, seg1d(m));
}
inline void upd(int node, int l, int r, int px, int py, long long val) {
if (l == r) {
a[node].upd(py, val);
return;
}
int m = (l + r) >> 1;
if (px <= m) upd(2 * node + 1, l, m, px, py, val);
else upd(2 * node + 2, m + 1, r, px, py, val);
a[node].upd2(py, a[node * 2 + 1], a[node * 2 + 2]);
}
inline void upd(int x, int y, long long val) {
upd(0, 1, n, x, y, val);
}
inline long long get(int node, int lx, int rx, int x1, int y1, int x2, int y2){
if (rx < x1 || x2 < lx) return 0;
if (x1 <= lx && rx <= x2) {
return a[node].get(y1, y2);
}
int m = (lx + rx) >> 1;
long long t1 = get(2 * node + 1, lx, m, x1, y1, x2, y2);
long long t2 = get(2 * node + 2, m + 1, rx, x1, y1, x2, y2);
return __gcd(t1, t2);
}
inline long long get(int x1, int y1, int x2, int y2) {
return get(0, 1, n, x1, y1, x2, y2);
}
} seg;
void init(int R, int C) {
n = R;
m = C;
seg.init(n, m);
// seg.resize(n * 4, vector<int>(m * 4));
}
void update(int p, int q, long long k) {
++p, ++q;
seg.upd(p, q, k);
}
long long calculate(int p, int q, int u, int v) {
++p, ++q, ++u, ++v;
return seg.get(p, q, u, 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... |