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<stdio.h>
#include "game.h"
typedef long long ll;
int x4,y4,x3,y3,n,m,x1,y1,x2,y2;
ll k;
ll gcd2(ll X, ll Y) {
if(X==0) return Y; if(Y==0) return X;
ll tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
void finding(int y1,int x,int y)
{
int mi;
x3=1; y3=m;
while(1)
{
mi=(x3+y3)/2;
if(y1<=mi) y3=mi;
else x3=mi+1;
if(x3<=x && y<=y3) x4=x3, y4=y3;
else break;
}
}
struct data
{
data *l,*r;
data(){l=r=NULL;}
void update3(int rx,int ry)
{
if(rx==ry){start2.update2(); return;}
int mid=(rx+ry)/2;
if(x1<=mid)
{
if(l==NULL) l=new data();
l->update3(rx,mid);
}
else
{
if(r==NULL) r=new data();
r->update3(mid+1,ry);
}
x2=y1; y2=y1;
if(r==NULL) k=l->start2.query2();
else if(l==NULL) k=r->start2.query2();
else k=gcd2(l->start2.query2(),r->start2.query2());
start2.update2();
}
ll query(int rx,int ry)
{
int mid=(rx+ry)/2;
if(x1<=rx && ry<=y1) return start2.query2();
if(x1>ry || y1<rx) return 0;
if(l==NULL && r==NULL) return 0;
else if(l==NULL) return r->query(mid+1,ry);
else if(r==NULL) return l->query(rx,mid);
return gcd2(l->query(rx,mid),r->query(mid+1,ry));
}
struct data2
{
ll val;
int cx,cy;
data2 *l,*r;
data2(){}
data2(ll v,int cx,int cy):val(v),cx(cx),cy(cy){l=r=NULL;}
void update2()
{
if(cy==0) cy=m;
if(cx==cy){val=k; return;}
int mid=(cx+cy)/2;
if(y1<=mid){
if(l==NULL) l=new data2(0,y1,y1);
else if(y1<l->cx)
{
data2 *p=l;
finding(y1,l->cx,l->cy);
l=new data2(0,x4,y4); l->r=p;
l->l=new data2(0,y1,y1);
}
else if(y1>l->cy)
{
data2 *p=l;
finding(y1,l->cx,l->cy);
l=new data2(0,x4,y4); l->l=p;
l->r=new data2(0,y1,y1);
}
l->update2();
}
else{
if(r==NULL) r=new data2(0,y1,y1);
else if(y1<r->cx)
{
data2 *p=r;
finding(y1,r->cx,r->cy);
r=new data2(0,x4,y4); r->r=p;
r->l=new data2(0,y1,y1);
}
else if(y1>r->cy)
{
data2 *p=r;
finding(y1,r->cx,r->cy);
r=new data2(0,x4,y4); r->l=p;
r->r=new data2(0,y1,y1);
}
r->update2();
}
if(r==NULL) val=l->val;
else if(l==NULL) val=r->val;
else val=gcd2(l->val,r->val);
}
ll query2()
{
if(cy==0) cy=m;
int mid=(cx+cy)/2;
if(cx>y2 || cy<x2) return 0;
if((x2<=cx && cy<=y2) || (l==NULL && r==NULL)) return val;
if(l==NULL) return r->query2();
else if(r==NULL) return l->query2();
return gcd2(l->query2(),r->query2());
}
};
data2 start2=data2(0,1,m);
};
void init(int R, int C){
n=R+1, m=C+1;
}
data start=data();
void update(int P, int Q, ll K){
x1=P+1; y1=Q+1; k=K;
start.update3(1,n);
}
ll calculate(int P, int Q, int U, int V){
x1=P+1; y1=U+1; x2=Q+1; y2=V+1;
return start.query(1,n);
}
# | 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... |