#pragma GCC optimize("Os")
#include "game.h"
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;
}
#include <assert.h>
int R, C;
struct Node{
long long val;
Node *l;
Node *r;
Node (){
val=0;
l=nullptr;
r=nullptr;
}
};
struct SegmentTree{
Node *root;
SegmentTree *l;
SegmentTree *r;
SegmentTree(){
root=new Node();
l=nullptr;
r=nullptr;
}
void update(Node *t, Node *tl, Node *tr, int l, int r, int pos, long long val, bool sussy){
if (l==r){
if (sussy) t->val=gcd2(tl?tl->val:0, tr?tr->val:0);
else t->val=val;
return;
}
int mid=(l+r)>>1;
if (pos<=mid){
if (!t->l) t->l=new Node();
update(t->l, tl?tl->l:nullptr, tr?tr->l:nullptr, l, mid, pos, val, sussy);
}else{
if (!t->r) t->r=new Node();
update(t->r, tl?tl->r:nullptr, tr?tr->r:nullptr, mid+1, r, pos, val, sussy);
}
t->val=gcd2(t->l?t->l->val:0, t->r?t->r->val:0);
}
long long get(Node *t, int l, int r, int L, int R){
if (r<L || R<l) return 0;
if (L<=l && r<=R) return t->val;
int mid=(l+r)>>1;
return gcd2(t->l?get(t->l, l, mid, L, R):0, t->r?get(t->r, mid+1, r, L, R):0);
}
};
struct SegmentTree2d{
SegmentTree *root;
SegmentTree2d(){
root=new SegmentTree();
}
void update(SegmentTree *t, int l, int r, int x, int y, long long val){
if (l!=r){
int mid=(l+r)>>1;
if (x<=mid){
if (!t->l) t->l=new SegmentTree();
update(t->l, l, mid, x, y, val);
}else{
if (!t->r) t->r=new SegmentTree();
update(t->r, mid+1, r, x, y, val);
}
}
t->update(t->root, t->l?t->l->root:nullptr, t->r?t->r->root:nullptr, 1, 1e9, y, val, l!=r);
}
long long get(SegmentTree *t, int l, int r, int lx, int rx, int ly, int ry){
if (rx<l || r<lx) return 0;
if (lx<=l && r<=rx) return t->get(t->root, 1, 1e9, ly, ry);
int mid=(l+r)>>1;
return gcd2(t->l?get(t->l, l, mid, lx, rx, ly, ry):0, t->r?get(t->r, mid+1, r, lx, rx, ly, ry):0);
}
} st;
void init(int _R, int _C) {
R=_R; C=_C;
int *ptr=nullptr;
assert(sizeof(ptr)==4);
}
void update(int P, int Q, long long K) {
++P; ++Q;
st.update(st.root, 1, 1e9, P, Q, K);
}
long long calculate(int P, int Q, int U, int V) {
++P; ++Q; ++U; ++V;
return st.get(st.root, 1, 1e9, P, U, Q, V);
}
Compilation message
game.c:20:4: error: unknown type name 'Node'
20 | Node *l;
| ^~~~
game.c:21:4: error: unknown type name 'Node'
21 | Node *r;
| ^~~~
game.c:22:4: error: expected specifier-qualifier-list before 'Node'
22 | Node (){
| ^~~~
game.c:30:4: error: unknown type name 'Node'
30 | Node *root;
| ^~~~
game.c:31:4: error: unknown type name 'SegmentTree'
31 | SegmentTree *l;
| ^~~~~~~~~~~
game.c:32:4: error: unknown type name 'SegmentTree'
32 | SegmentTree *r;
| ^~~~~~~~~~~
game.c:33:4: error: expected specifier-qualifier-list before 'SegmentTree'
33 | SegmentTree(){
| ^~~~~~~~~~~
game.c:63:4: error: unknown type name 'SegmentTree'
63 | SegmentTree *root;
| ^~~~~~~~~~~
game.c:64:4: error: expected specifier-qualifier-list before 'SegmentTree2d'
64 | SegmentTree2d(){
| ^~~~~~~~~~~~~
game.c: In function 'init':
game.c:90:13: error: 'nullptr' undeclared (first use in this function)
90 | int *ptr=nullptr;
| ^~~~~~~
game.c:90:13: note: each undeclared identifier is reported only once for each function it appears in
game.c: In function 'update':
game.c:96:6: error: 'struct SegmentTree2d' has no member named 'update'
96 | st.update(st.root, 1, 1e9, P, Q, K);
| ^
game.c: In function 'calculate':
game.c:101:13: error: 'struct SegmentTree2d' has no member named 'get'
101 | return st.get(st.root, 1, 1e9, P, U, Q, V);
| ^
game.c:102:1: warning: control reaches end of non-void function [-Wreturn-type]
102 | }
| ^