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;
}
const int MAXN = 1e5 + 10;
long long st[10][4 * MAXN];
void u(int l, int r, int row, int tar, int idx, long long val) {
if(l == r) {
st[row][idx] = val;
return;
}
int mid = (l + r) >> 1;
if(tar <= mid) u(l, mid, row, tar, (idx<<1) + 1, val);
else u(mid+1, r, row, tar, (idx<<1) + 2, val);
st[row][idx] = gcd2(st[row][(idx<<1) + 1], st[row][(idx<<1) + 2]);
}
long long qu(int l, int r, int constl, int constr, int row, int idx) {
if(l <= constl && constr <= r) return st[row][idx];
int mid = (constl + constr) >> 1;
if(mid < l || r < constl) return qu(l, r, mid+1, constr, row, (idx<<1) + 2);
else if(constr < l || r < mid+1) return qu(l, r, constl, mid, row, (idx<<1) + 1);
else {
return gcd2(qu(l, r, constl, mid, row, (idx<<1) + 1), qu(l, r, mid+1, constr, row, (idx<<1) + 2));
}
}
long long st2[2000][2000][11];
int r, c;
void init(int R, int C) {
r = R;
c = C;
}
long long qry(int i, int l, int r) {
int k = 32 - __builtin_clz(r - l + 1) - 1;
return gcd2(st2[i][l][k], st2[i][r - (1<<k) + 1][k]);
}
void update(int P, int Q, long long K) {
if(max(r, c) <= 2000) {
st2[P][Q][0] = K;
for(int i=1; i<=10; i++) {
for(int j=0; j+(1<<i)-1<c; j++) {
st2[P][j][i] = gcd2(st2[P][j][i-1], st2[P][j + (1<<(i-1))][i-1]);
}
}
return;
}
u(0, c - 1, P, Q, 0, K);
}
long long calculate(int P, int Q, int U, int V) {
if(max(r, c) <= 2000) {
long long ans = 0;
for(int i=P; i<=U; i++) {
ans = gcd2(ans, qry(i, Q, V));
}
return ans;
}
long long ans = 0;
for(int i=P; i<=U; i++) ans = gcd2(ans, qu(Q, V, 0, c - 1, i, 0));
return ans;
}
/*
g++ -std=c++17 -O2 -o T2444 grador.cpp T2444.cpp
./T2444 < input.txt
*/
# | 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... |