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;
long long gcd2(long long X, long long Y) {
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
struct Ty{
int l,r;
Ty* left;
Ty* right;
long long val;
Ty(){};
Ty(int l, int r){
this->l=l;
this->r=r;
this->left=NULL;
this->right=NULL;
this->val=0LL;
}
};
struct Tx{
int l,r;
Tx* left;
Tx* right;
Ty t;
Tx(){};
Tx(int l, int r){
this->l=l;
this->r=r;
this->left=NULL;
this->right=NULL;
this->t=Ty(0,999999999);
}
}*root;
void update2(Ty* node, int j, long long val){
if (node->l>j||node->r<j)
return;
if (node->l==node->r){
node->val=val;
return;
}
int mid=(node->l+node->r)>>1;
if (mid>=j){
if (node->left==NULL)
node->left=new Ty(node->l,mid);
update2(node->left,j,val);
}
else{
if (node->right==NULL&&mid<j)
node->right=new Ty(mid+1,node->r);
update2(node->right,j,val);
}
node->val=gcd2((node->left==NULL?0:node->left->val),(node->right==NULL?0:node->right->val));
}
long long get2(Ty* node, int u, int v){
if (node==NULL||node->l>v||node->r<u)
return 0;
if (node->l>=u&&node->r<=v)
return node->val;
return gcd2(get2(node->left,u,v),get2(node->right,u,v));
}
void update(Tx* node, int i, int j, long long val){
if (node->l==node->r){
update2(&node->t,j,val);
return;
}
int mid=(node->l+node->r)>>1;
if (mid>=i){
if (node->left==NULL)
node->left=new Tx(node->l,mid);
update(node->left,i,j,val);
}
else{
if (node->right==NULL)
node->right=new Tx(mid+1,node->r);
update(node->right,i,j,val);
}
update2(&node->t,j,gcd2(node->left?get2(&node->left->t,j,j):0,node->right?get2(&node->right->t,j,j):0));
}
long long get(Tx* node, int i, int j, int u, int v){
if (node==NULL||node->l>j||node->r<i)
return 0;
if (node->l>=i&&node->r<=j)
return get2(&node->t,u,v);
return gcd2(get(node->left,i,j,u,v),get(node->right,i,j,u,v));
}
void init(int R, int C){
root=new Tx(0,R-1);
}
void update(int P, int Q, long long K){
update(root,P,Q,K);
}
long long calculate(int P, int Q, int U, int V){
return get(root,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... |