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 <iostream>
#include <vector>
#define ll long long
using namespace std;
int r,c;
ll grid[2001][10001];
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;
}
void init(int R, int C) {
r = R;c = C;
for(int i=0;i<2001;i++)for(int j=0;j<10001;j++)grid[i][j] = 0;
}
void updater(int i,int pos,int l,int r,int idx,ll k){
if(l == r){
grid[i][pos] = k;
return;
}
int mid = (l+r)/2;
if(idx<=mid){
updater(i,2*pos+1,l,mid,idx,k);
}else{
updater(i,2*pos+2,mid+1,r,idx,k);
}
grid[i][pos] = gcd2(grid[i][2*pos+1],grid[i][2*pos+2]);
}
ll asker(int i,int pos,int l,int r,int ql,int qr){
if(ql>r || qr<l)return 0;
if(ql <= l && r <= qr){
return grid[i][pos];
}
int mid = (l+r)/2;
return gcd2(asker(i,2*pos+1,l,mid,ql,qr),asker(i,2*pos+2,mid+1,r,ql,qr));
}
void update(int P, int Q, long long K) {
updater(P,0,0,c-1,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
ll val = 0;
for(int i=P;i<=U;i++){
val = gcd2(val,asker(i,0,0,c-1,Q,V));
}
return val;
}
# | 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... |