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;
int R, C, N, ch, P, Q, U, V;
int px, qx;
int xco, yco;
long long K;
struct Y
{
Y *left, *right;
long long val;
int only;
Y()
{
left = right = NULL;
val = 0ll;
only = -1;
}
};
struct X
{
X *left, *right;
Y *ynode;
X()
{
left = right = NULL;
ynode = NULL;
}
} * inix;
long long gcd2(long long xx, long long yy)
{
if (yy == 0)
return xx;
return gcd2(yy, xx % yy);
}
void yup(Y *y, int s, int e, long long v)
{
int m = (s + e) >> 1;
if (y->only == -1)
{
y->val = v;
y->only = yco;
return;
}
else if (y->only >= 0)
{
if (y->only == yco)
{
y->val = v;
return;
}
else
{
if (y->only <= m)
{
y->left = new Y();
y->left->val = y->val;
y->left->only = y->only;
}
else
{
y->right = new Y();
y->right->val = y->val;
y->right->only = y->only;
}
y->only = -2;
}
}
if (m >= yco)
{
if (!y->left)
{
y->left = new Y();
}
yup(y->left, s, m, v);
}
else
{
if (!y->right)
{
y->right = new Y();
}
yup(y->right, m + 1, e, v);
}
long long l = 0, r = 0;
if (y->left)
l = y->left->val;
if (y->right)
r = y->right->val;
y->val = gcd2(l, r);
}
long long yans(Y *y, int s, int e, int py, int qy)
{
int m = (s + e) >> 1;
if ((!y) || s > qy || e < py)
return 0ll;
if (py <= s && e <= qy)
return y->val;
if (y->only >= 0)
{
if (py <= y->only && y->only <= qy)
{
return y->val;
}
else
return 0ll;
}
long long l = 0, r = 0;
if (y->left)
l = yans(y->left, s, m, py, qy);
if (y->right)
r = yans(y->right, m + 1, e, py, qy);
return gcd2(l, r);
}
void xup(X *x, int s, int e, long long v)
{
int m = (s + e) >> 1;
if (!x->ynode)
x->ynode = new Y();
if (s != e)
{
if (m >= xco)
{
if (!x->left)
{
x->left = new X();
}
xup(x->left, s, m, v);
}
else
{
if (!x->right)
{
x->right = new X();
}
xup(x->right, m + 1, e, v);
}
}
long long realv;
if (s == e)
realv = v;
else
{
realv = gcd2(x->left ? yans(x->left->ynode, 0, C - 1, yco, yco) : 0, x->right ? yans(x->right->ynode, 0, C - 1, yco, yco) : 0);
}
yup(x->ynode, 0, C - 1, realv);
}
long long xans(X *x, int s, int e, int px, int qx, int py, int qy)
{
int m = (s + e) >> 1;
if ((!x->ynode) || s > qx || e < px)
return 0ll;
if (px <= s && e <= qx)
{
return yans(x->ynode, 0, C - 1, py, qy);
}
long long l = 0, r = 0;
if (x->left)
l = xans(x->left, s, m, px, qx, py, qy);
if (x->right)
r = xans(x->right, m + 1, e, px, qx, py, qy);
return gcd2(l, r);
}
void init(int RR, int CC)
{
R = RR;
C = CC;
inix = new X();
}
void update(int P, int Q, long long K)
{
xco = P;
yco = Q;
xup(inix, 0, R - 1, K);
}
long long calculate(int P, int Q, int U, int V)
{
return xans(inix, 0, R - 1, P, U, Q, 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... |