#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int R, C;
LL GCD(LL A, LL B){
if (!B) return A;
return GCD(B, A%B);
}
struct Ynode{
LL val=0;
Ynode *lc=NULL, *rc=NULL;
void update(int s, int e, int t, LL v){
if (e < t || t < s) return;
if(s == e){
val = v;
return;
}
int mid = (s+e)/2;
if (lc == NULL) lc = new Ynode;
if (rc == NULL) rc = new Ynode;
lc->update(s, mid, t, v);
rc->update(mid+1, e, t, v);
val = GCD(lc->val, rc->val);
}
LL query(int s, int e, int ts, int te){
if (te < s || e < ts) return 0;
if (ts <= s && e <= te) return val;
int mid = (s+e)/2;
if (lc != NULL) return GCD(lc->query(s, mid, ts, te), rc->query(mid+1, e, ts, te));
return 0;
}
};
struct Xnode{
Ynode *Ytree=NULL;
Xnode *lc=NULL, *rc=NULL;
LL update(int s, int e, int xt, int yt, LL v){
if (e < xt || xt < s) return Ytree->query(0, C-1, yt, yt);
if(s == e){
Ytree->update(0, C-1, yt, v);
return v;
}
int mid = (s+e)/2;
if (lc == NULL){
lc = new Xnode;
lc->Ytree = new Ynode;
}
if (rc == NULL){
rc = new Xnode;
rc->Ytree = new Ynode;
}
LL ret = lc->update(s, mid, xt, yt, v);
ret = GCD(ret, rc->update(mid+1, e, xt, yt, v));
Ytree->update(0, C-1, yt, ret);
return ret;
}
LL query(int s, int e, int xts, int xte, int yts, int yte){
if (xte < s || e < xts) return 0;
if (xts <= s && e <= xte) return Ytree->query(0, C-1, yts, yte);
int mid = (s+e)/2;
if (lc != NULL) return GCD(lc->query(s, mid, xts, xte, yts, yte), rc->query(mid+1, e, xts, xte, yts, yte));
return 0;
}
} *Xtree;
void init(int r, int c){
R = r, C = c;
Xtree = new Xnode;
Xtree->Ytree = new Ynode;
}
void update(int x, int y, LL k){
Xtree->update(0, R-1, x, y, k);
}
LL calculate(int x1, int y1, int x2, int y2){
return Xtree->query(0, R-1, x1, x2, y1, y2);
}
Compilation message
grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
int res;
^~~
/tmp/cc6iMZWH.o: In function `main':
grader.c:(.text.startup+0x5d): undefined reference to `init'
grader.c:(.text.startup+0xb8): undefined reference to `calculate'
grader.c:(.text.startup+0x122): undefined reference to `update'
collect2: error: ld returned 1 exit status