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;
long long K;
struct Y
{
Y *left, *right ;
Y(){left=right=NULL;val=0;}
long long val;
};
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,int yco, long long v)
{
if (s == e)
{
y->val = v;
return;
}
if ((s + e) / 2 >= yco)
{
if (!y->left)
{
y->left=new Y();
}
yup(y->left, s,(s+e)/2,yco, v);
}
else
{
if (!y->right)
{
y->right=new Y();
}
yup(y->right, (s+e)/2+1,e,yco, 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);
}
void hardyup(Y *y, int s,int e, Y *ly, Y *ry, int yco)
{
Y *nextl=NULL, *nextr=NULL;
long long l = 0, r = 0;
if (ly)
{
l =ly->val;
}
if (ry)
{
r = ry->val;
}
y->val = gcd2(l, r);
if (s == e)
return;
if (yco <= (s + e) / 2)
{
if (ly)
nextl = ly->left;
if(ry)
nextr=ry->left;
if (!y->left)
{
y->left = new Y();
}
hardyup(y->left, s,(s+e)/2,nextl, nextr, yco);
}
else
{
if (ly)
nextl = ly->right;
if(ry)
nextr=ry->right;
if (!y->right)
{
y->right = new Y();
}
hardyup(y->right, (s+e)/2+1,e,nextl, nextr, yco);
}
}
void xup(X *x, int s,int e,int xco, int yco, long long v)
{
if(!x->ynode)x->ynode=new Y();
if (s == e)
{
yup(x->ynode, 0,C-1,yco, v);
return;
}
if ((s + e) / 2 >= xco)
{
if (!x->left)
{
x->left = new X();
}
xup(x->left, s,(s+e)/2+1,xco, yco, v);
}
else
{
if (!x->right)
{
x->right = new X();
}
xup(x->right, (s+e)/2+1,e,xco, yco, v);
}
Y *ly=NULL,*ry=NULL;
if (x->left)
ly= x->left->ynode;
if (x->right)
ry=x->right->ynode;
hardyup(x->ynode, 0,C-1,ly, ry, yco);
}
long long yans(Y *y, int s,int e,int py, int qy)
{
if (s > qy || e < py)
return 0ll;
if (py <= s && e <= qy)
return y->val;
long long l = 0, r = 0;
if (y->left)
l = yans(y->left,s,(s+e)/2, py, qy);
if (y->right)
r = yans(y->right, (s+e)/2+1,e,py, qy);
return gcd2(l, r);
}
long long xans(X *x, int s,int e, int px, int qx, int py, int qy)
{
if(!x->ynode)
return 0ll;
if (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,(s+e)/2,px, qx, py, qy);
if (x->right)
r = xans(x->right,(s+e)/2+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)
{
xup(inix, 0,R-1,P, Q, 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... |