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;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=2001;
int a,b;
ll tree[4*mxn][4*mxn],arr[mxn][mxn];
long long gcd(long long X, long long Y) {
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
struct st{
//vector<vector<ll>>tree;
//vector<vector<ll>>arr;
int n,m;
void give_size(int x,int y){
n=x,m=y;
//tree.resize(4*n+5,vector<ll>(4*m+5));
//arr.resize(n+5,vector<ll>(m+5));
}
void buildy(int &nodex,int &lx,int &rx,int nodey,int ly,int ry){
if(ly==ry){
if(lx==rx){
tree[nodex][nodey]=arr[lx][ly];
}
else{
tree[nodex][nodey]=gcd(tree[2*nodex][nodey],tree[2*nodex+1][nodey]);
}
}
else{
int my=(ly+ry)/2;
buildy(nodex,lx,rx,2*nodey,ly,my);
buildy(nodex,lx,rx,2*nodey+1,my+1,ry);
tree[nodex][nodey]=gcd(tree[nodex][2*nodey],tree[nodex][2*nodey+1]);
}
}
void buildx(int node,int l,int r){
if(l!=r){
int mx=(l+r)/2;
buildx(2*node,l,mx);
buildx(2*node+1,mx+1,r);
}
buildy(node,l,r,1,l,m);
}
void updatey(int &nodex,int &lx,int &rx,int nodey,int ly,int ry,int &x,int &y,ll &val){
if(ly==ry){
if(lx==rx){
tree[nodex][nodey]=val;
}
else{
tree[nodex][nodey]=gcd(tree[nodex*2][nodey],tree[nodex*2+1][nodey]);
}
}
else{
int my=(ly+ry)/2;
if(y<=my){
updatey(nodex,lx,rx,2*nodey,ly,my,x,y,val);
}
else{
updatey(nodex,lx,rx,2*nodey+1,my+1,ry,x,y,val);
}
tree[nodex][nodey]=gcd(tree[nodex][2*nodey],tree[nodex][2*nodey+1]);
}
}
void updatex(int node,int l,int r,int &x,int &y,ll &val){
if(l!=r){
int mx=(l+r)/2;
if(x<=mx){
updatex(2*node,l,mx,x,y,val);
}
else{
updatex(2*node+1,mx+1,r,x,y,val);
}
}
updatey(node,l,r,1,1,m,x,y,val);
}
ll query_y(int &nodex,int nodey,int l,int r,int &ql,int &qr){
if(l>r) return 0;
if(l>qr||r<ql) return 0;
if(ql<=l&&r<=qr) return tree[nodex][nodey];
int my=(l+r)/2;
ll left=query_y(nodex,nodey*2,l,my,ql,qr);
ll right=query_y(nodex,nodey*2+1,my+1,r,ql,qr);
return gcd(left,right);
}
ll query_x(int node,int l,int r,int &ql,int &qr,int &qly,int &qry){
if(l>r) return 0;
if(l>qr||r<ql) return 0;
if(ql<=l&&r<=qr){
return query_y(node,1,1,m,qly,qry);
}
int mx=(l+r)/2;
ll left=query_x(2*node,l,mx,ql,qr,qly,qry);
ll right=query_x(2*node+1,mx+1,r,ql,qr,qly,qry);
return gcd(left,right);
}
};
st tree1;
void init(int R, int C) {
a=R,b=C;
tree1.give_size(R,C);
tree1.buildx(1,1,a);
}
void update(int P, int Q, long long K) {
P++,Q++;
tree1.updatex(1,1,a,P,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
P++,U++,Q++,V++;
return tree1.query_x(1,1,a,P,U,Q,V);
}
/*
g++ game.cpp grader.c ; .\a.exe
2 3 9
1 0 0 20
1 0 2 15
1 1 1 12
2 0 0 0 2
2 0 0 1 1
1 0 1 6
1 1 1 14
2 0 0 0 2
2 0 0 1 1
*/
# | 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... |