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 <bits/stdc++.h>
using namespace std;
using u32 = uint32_t;
using u64 = uint64_t;
u32 R, C;
struct DynamicSegTree2D{
unordered_map<u32, unordered_map<u32, u64>> seg;
void set(u32 i, u32 j, u64 x){
seg[i][j] = x;
for(int jj = j; jj >>= 1; ) seg[i][jj] = gcd(seg[i][jj << 1], seg[i][jj << 1 | 1]);
for(int ii = i; ii >>= 1; ) seg[ii][j] = gcd(seg[ii << 1][j], seg[ii << 1 | 1][j]);
for(int ii = i; ii >>= 1; ){
auto& s = seg[ii];
for(int jj = j; jj >>= 1; ) s[jj] = gcd(s[jj << 1], s[jj << 1 | 1]);
}
}
u64 get(const unordered_map<u32, u64>& s, u32 j) const {
auto p = s.find(j);
if(p == s.end()) return 0;
return p->second;
}
u64 get(u32 i, u32 l, u32 r) const {
auto p = seg.find(i);
if(p == seg.end()) return 0;
auto& s = p->second;
u64 ans = 0;
while(l < r){
if(l & 1) ans = gcd(ans, get(s, l++));
if(r & 1) ans = gcd(ans, get(s, --r));
l >>= 1;
r >>= 1;
}
return ans;
}
u64 get(u32 l, u32 r, u32 y_l, u32 y_r) const {
u64 ans = 0;
while(l < r){
if(l & 1) ans = gcd(ans, get(l++, y_l, y_r));
if(r & 1) ans = gcd(ans, get(--r, y_l, y_r));
l >>= 1;
r >>= 1;
}
return ans;
}
} seg;
extern "C" {
void init(int R_, int C_){
R = 1;
C = 1;
while(R < R_) R <<= 1;
while(C < C_) C <<= 1;
}
void update(int P, int Q, long long K){
P += R;
Q += C;
seg.set(P, Q, K);
}
long long calculate(int P, int Q, int U, int V){
P += R;
Q += C;
U += R + 1;
V += C + 1;
return seg.get(P, U, Q, V);
}
}
Compilation message (stderr)
game.cpp: In function 'void init(int, int)':
game.cpp:53:13: warning: comparison of integer expressions of different signedness: 'u32' {aka 'unsigned int'} and 'int' [-Wsign-compare]
53 | while(R < R_) R <<= 1;
| ~~^~~~
game.cpp:54:13: warning: comparison of integer expressions of different signedness: 'u32' {aka 'unsigned int'} and 'int' [-Wsign-compare]
54 | while(C < C_) C <<= 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... |