#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define mid (l + r) / 2
#define AC main
using namespace std;
int R, C;
int gcd(int a, int b){
if(!b) return a;
if(!a) return b;
return gcd(b, a % b);
}
struct segleaf{
int val;
pair<int, int> tag;
segleaf *lc, *rc;
segleaf(){lc = rc = nullptr, val = 0, tag = {0, 0};}
segleaf(int v, int y){lc = rc = nullptr, val = v, tag = {v, y};}
inline void pull(){
val = gcd((lc? lc->val : 0), (rc? rc->val : 0));
}
inline void push(int m){
if(tag.ff){
if(tag.ss <= m) lc = new segleaf(tag.ff, tag.ss);
else rc = new segleaf(tag.ff, tag.ss);
tag = {0, 0};
}
}
void update(int y, int l, int r, int v){
if(y == l && y == r){
val = v;
return;
}
push(mid);
if(y <= mid){
if(!lc)lc = new segleaf(v, y);
else lc->update(y, l, mid, v);
}else{
if(!rc) rc = new segleaf(v, y);
else rc->update(y, mid + 1, r, v);
}
pull();
}
int query(int up, int down, int l, int r){
if(tag.ff){
if(tag.ss >= up && tag.ss <= down) return val;
else return 0;
}
if(up == l && down == r) return val;
push(mid);
if(down <= mid) return (lc? lc->query(up, down, l, mid) : 0);
else if(up > mid) return (rc? rc->query(up, down, mid + 1, r) : 0);
else return gcd((lc? lc->query(up, mid, l, mid) : 0), (rc? rc->query(mid + 1, down, mid + 1, r) : 0));
}
};
struct segtree{
segleaf s;
segtree *lc, *rc;
segtree(){lc = rc = nullptr;}
inline void pull(int y){
s.update(y, 0, C - 1, gcd((lc? lc->s.query(y, y, 0, C - 1) : 0), (rc? rc->s.query(y, y, 0, C - 1) :0)));
}
void update(int x, int y, int l, int r, int v){
if(x == l && x == r){
s.update(y, 0, C - 1, v);
return;
}
if(x <= mid){
if(!lc) lc = new segtree;
lc->update(x, y, l, mid, v);
}else{
if(!rc) rc = new segtree;
rc->update(x, y, mid + 1, r, v);
}
pull(y);
}
int query(int left, int right, int up, int down, int l, int r){
if(left == l && right == r) return s.query(up, down, 0, C - 1);
else if(right <= mid) return (lc? lc->query(left, right, up, down, l, mid) : 0);
else if(left > mid) return (rc? rc->query(left, right, up, down, mid + 1, r) : 0);
else return gcd((lc? lc->query(left, mid, up, down, l, mid) : 0), (rc? rc->query(mid + 1, right, up, down, mid + 1, r) : 0));
}
};
signed AC(){
cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);
int N, t, l, r, u, d, v;
segtree root;
cin >> R >> C >> N;
while(N--){
cin >> t >> l >> u;
if(t == 1){
cin >> v;
root.update(l, u, 0, R - 1, v);
}else{
cin >> r >> d;
cout << root.query(l, r, u, d, 0, R - 1) << "\n";
}
}
return 0;
}
Compilation message
/tmp/cc4ZfcO1.o: In function `main':
game.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccmrRcDF.o:grader.c:(.text.startup+0x0): first defined here
/tmp/ccmrRcDF.o: In function `main':
grader.c:(.text.startup+0x85): undefined reference to `init'
grader.c:(.text.startup+0xe8): undefined reference to `calculate'
grader.c:(.text.startup+0x156): undefined reference to `update'
collect2: error: ld returned 1 exit status