#include "game.h"
#include <stdio.h>
#include <stdlib.h>
#define lld long long
long long gcd2(long long X, long long Y) {
long long tmp;
if(X == 0) return Y;
if(Y == 0) return X;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
struct datay{
lld value;
datay *left,*right;
datay(){
value = 0;
left = right = NULL;
}
};
struct datax{
datax *left,*right;
datay *yroot;
datax(){
left = right = NULL;
}
}*xroot;
lld R,C;
long long nr,nc;
void init(int iR, int iC) {
R = (lld)iR; C = (lld)iC;
for(nr = 1; nr < R; nr *= 2);
for(nc = 1; nc < C; nc *= 2);
xroot = new datax();
xroot -> yroot = new datay();
}
lld ans;
lld findx,findy,value;
void yupdate(datay *node,lld left,lld right){
node -> value = gcd2(node->value,value);
if(left == right) return;
lld mid = (left+right)/2;
if(left <= findy && findy <= mid){
if(node -> left == NULL) node -> left = new datay();
yupdate(node->left,left,mid);
}
if(mid+1 <= findy && findy <= right){
if(node -> right == NULL) node -> right = new datay();
yupdate(node->right,mid+1,right);
}
}
void xupdate(datax *node,lld left,lld right){
if(node -> yroot == NULL) node -> yroot = new datay();
yupdate(node -> yroot,1,nc);
if(left == right) return;
lld mid = (left+right)/2;
if(left <= findx && findx <= mid){
if(node -> left == NULL) node -> left = new datax();
xupdate(node->left,left,mid);
}
if(mid+1 <= findx && findx <= right){
if(node -> right == NULL) node -> right = new datax();
xupdate(node->right,mid+1,right);
}
}
void update(int iP, int iQ, long long K) {
lld P,Q;
P = (lld)iP; Q = (lld)iQ;
P++; Q++;
findx = P;
findy = Q;
value = K;
xupdate(xroot,1,nr);
}
lld sx,ex,sy,ey;
bool crossy(lld left,lld right){
if(ey < left || right < sy) return false;
return true;
}
void ycalc(datay *node,lld left,lld right){
if(sy <= left && right <= ey){
ans = gcd2(ans,node->value);
return;
}
lld mid = (left+right)/2;
if(crossy(left,mid) && node->left != NULL) ycalc(node->left,left,mid);
if(crossy(mid+1,right) && node->right != NULL) ycalc(node->right,mid+1,right);
}
bool crossx(lld left,lld right){
if(ex < left || right < sx) return false;
return true;
}
void xcalc(datax *node,lld left,lld right){
if(sx <= left && right <= ex){
ycalc(node->yroot,1,nc);
return;
}
lld mid = (left+right)/2;
if(crossx(left,mid) && node -> left != NULL) xcalc(node->left,left,mid);
if(crossx(mid+1,right) && node -> right != NULL) xcalc(node->right,mid+1,right);
}
long long calculate(int iP, int iQ, int iU, int iV) {
lld i,j;
lld P,Q,U,V;
P = (lld)iP; Q = (lld)iQ; U = (lld)iU; V = (lld)iV;
P++; Q++; U++; V++;
ans = 0;
sx = P; ex = U;
sy = Q; ey = V;
xcalc(xroot,1,nr);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |