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;
long long gcd(long long a,long long b){
while (b) b^=a^=b^=a%=b;
return a;
}
long long n,m;
long long seg[8010][8010];
void updateY(int idX,int tlX,int trX,int idY,int tlY,int trY,int xp,int yp,long long val){
if (tlY==trY){
if (tlX==trX) seg[idX][idY]=val;
else seg[idX][idY]=gcd(seg[2*idX][idY],seg[2*idX+1][idY]);
return;
}
int tmY=(tlY+trY)/2;
if (yp<=tmY) updateY(idX,tlX,trX,2*idY,tlY,tmY,xp,yp,val);
else updateY(idX,tlX,trX,2*idY+1,tmY+1,trY,xp,yp,val);
seg[idX][idY]=gcd(seg[idX][2*idY],seg[idX][2*idY+1]);
}
void updateX(int idX,int tlX,int trX,int xp,int yp,long long val){
if (tlX!=trX){
int tmX=(tlX+trX)/2;
if (xp<=tmX) updateX(2*idX,tlX,tmX,xp,yp,val);
else updateX(2*idX+1,tmX+1,trX,xp,yp,val);
}
updateY(idX,tlX,trX,1,1,m,xp,yp,val);
}
void updateEE(int xp,int yp,int val){
updateX(1,1,n,xp,yp,val);
}
long long queryY(int idX,int idY,int tlY,int trY,int lY,int rY){
if (lY>rY) return 0ll;
if (lY<=tlY&&trY<=rY) return seg[idX][idY];
int tmY=(tlY+trY)/2;
return gcd(queryY(idX,2*idY,tlY,tmY,lY,min(rY,tmY)),queryY(idX,2*idY+1,tmY+1,trY,max(lY,tmY+1),rY));
}
long long queryX(int idX,int tlX,int trX,int lX,int rX,int lY,int rY){
if (lX>rX) return 0ll;
if (lX<=tlX&&trX<=rX) return queryY(idX,1,1,m,lY,rY);
int tmX=(tlX+trX)/2;
return gcd(queryX(2*idX,tlX,tmX,lX,min(rX,tmX),lY,rY),queryX(2*idX+1,tmX+1,trX,max(lX,tmX+1),rX,lY,rY));
}
long long query(int lx,int rx,int ly,int ry){
return queryX(1,1,n,lx,rx,ly,ry);
}
void init(int R, int C) {
n=R;
m=C;
}
void update(int P, int Q, long long K) {
P++; Q++;
updateEE(P,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
P++; Q++; U++; V++;
return query(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... |