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/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long long long
#define sz(x) int((x).size())
struct N1 {
int lc, rc, v;
} h1[(100 << 20) / sizeof(N1)];
struct N2 {
int lc, rc;
long v;
} h2[(100 << 20) / sizeof(N2)];
int alloc1() {
static int hind = 1;
return hind++;
}
int alloc2() {
static int hind = 1;
return hind++;
}
int n, m, root;
extern "C" void init(int _n, int _m) {
n = _n;
m = _m;
}
void update2(int& o, int l, int r, int y, long v) {
if (!o) {
o = alloc2();
}
if (l == r) {
h2[o].v = v;
return;
}
int mid = (l + r) / 2;
auto& [lc, rc, cv] = h2[o];
if (y <= mid) {
update2(lc, l, mid, y, v);
} else {
update2(rc, mid + 1, r, y, v);
}
cv = gcd(h2[lc].v, h2[rc].v);
}
void update1(int& o, int l, int r, int x, int y, long v) {
if (!o) {
o = alloc1();
}
auto& [lc, rc, cv] = h1[o];
update2(cv, 0, m - 1, y, v);
if (l == r) {
return;
}
int mid = (l + r) / 2;
if (x <= mid) {
update1(lc, l, mid, x, y, v);
} else {
update1(rc, mid + 1, r, x, y, v);
}
}
extern "C" void update(int x, int y, long v) {
update1(root, 0, n - 1, x, y, v);
}
long query2(int o, int l, int r, int ql, int qr) {
if (!o) {
return 0;
} else if (l <= ql && r <= qr) {
return h2[o].v;
}
auto& [lc, rc, _] = h2[o];
int mid = (l + r) / 2;
long ans = 0;
if (ql <= mid) {
ans = query2(lc, l, mid, ql, qr);
}
if (mid < qr) {
ans = gcd(ans, query2(rc, mid + 1, r, ql, qr));
}
return ans;
}
long query1(int o, int l, int r, int ql, int qr, int ql2, int qr2) {
if (!o) {
return 0;
} else if (l <= ql && r <= qr) {
return query2(h1[o].v, 0, m - 1, ql2, qr2);
}
auto& [lc, rc, _] = h1[o];
int mid = (l + r) / 2;
long ans = 0;
if (ql <= mid) {
ans = query1(lc, l, mid, ql, qr, ql2, qr2);
}
if (mid < qr) {
ans = gcd(ans, query1(rc, mid + 1, r, ql, qr, ql2, qr2));
}
return ans;
}
extern "C" long calculate(int x1, int y1, int x2, int y2) {
return query1(root, 0, n - 1, x1, x2, y1, y2);
}
# | 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... |