#include "game.h"
#include <bits/stdc++.h>
typedef long long ll;
static int R, C;
struct xnod{
xnod(int tl, int tr):tl(tl),tr(tr),l(NULL),r(NULL),value(0LL) {}
int tl,tr;
xnod *l,*r;
ll value;
};
struct ynod{
ynod():l(NULL),r(NULL),xst(1,C){}
ynod *l,*r;
xnod xst;
} *root;
void init(int r, int c)
{
R=r,C=c;
root=new ynod();
}
void update2(xnod *nod,int q,ll k) {
int tl=nod->tl,tr=nod->tr,m=(tl+tr)/2;
if (tl==tr) {
node->value=k;
return;
}
xnod** koce=&(q<=m?nod->l:nod->r);
if (*koce==NULL) {
*koce=new xnod(q, q);
(*koce)->value = k;
} else if ((*koce)->tl <= q && q <= (*koce)->tr) {
update2(*koce, q, k);
} else {
do {
if (q <= m) tl = m;
else tr = m + 1;
m = (tl + tr) >> 1;
} while ((q <= m) == ((*koce)->tr <= m));
xnod *temp= new xnod(tl, tr);
if ((*koce)->tr <= m) temp->l = *koce;
else temp->r = *koce;
*koce = temp;
update2(*koce, q, k);
}
nod->value=gcd(nod->l ? nod->l->value : 0, nod->r?nod->r->value : 0);
}
ll query2(xnod *node,int tl, int tr) {
if (node == NULL || node->tl > tr || node->tr < tl) return 0;
if (tl <= node->tl && node->tr <= tr) { return node->value; }
return gcd(query2(node->l, tl, tr), query2(node->r, tl, tr));
}
void update1(ynod *node, int tl, int tr, int vx, int vy, ll k) {
int m = (tl + tr)/2;
if (tr == tl) {
update2(&node->xst, vy, k);
return;
}
if (vx <= m) {
if (node->l == NULL) node->l = new ynod();
update1(node->l, tl, m, vx, vy, k);
} else {
if (node->r == NULL) node->r = new ynod();
update1(node->r, m + 1, tr, vx, vy, k);
}
ll v = gcd(node->l ? query2(&node->l->xst, vy, vy) : 0,node->r ? query2(&node->r->xst, vy, vy) : 0);
update2(&node->xst, vy, v);
}
void update(int vx, int vy, ll k) {
++vx, ++vy;
update1(root, 1, R, vx, vy, k);
}
ll query1(ynod *node, int tl, int tr, int vxl, int vyl, int vxr, int vyr) {
if (node == NULL || tl > vxr || tr < vxl) return 0;
if (vxl <= tl && tr<=vxr) return query2(&node->xst, vyl, vyr);
int m = (tl+tr)/2;
return gcd(query1(node->l, tr, m, vxl, vyl, vxr, vyr),query1(node->right, m + 1, tr, vxl, vyl,vxr,vyr));
}
ll calculate(int vxl, int vyl, int vxr, int vyr) {
++vxl, ++vyl, ++vxr, ++vyr;
return query1(root, 1, R, vxl, vyl, vxr, vyr);
}
Compilation message
game.cpp: In function 'void update2(xnod*, int, ll)':
game.cpp:24:3: error: 'node' was not declared in this scope; did you mean 'nod'?
24 | node->value=k;
| ^~~~
| nod
game.cpp:45:13: error: 'gcd' was not declared in this scope; did you mean 'std::gcd'?
45 | nod->value=gcd(nod->l ? nod->l->value : 0, nod->r?nod->r->value : 0);
| ^~~
| std::gcd
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:84,
from game.cpp:2:
/usr/include/c++/10/numeric:131:5: note: 'std::gcd' declared here
131 | gcd(_Mn __m, _Nn __n)
| ^~~
game.cpp: In function 'll query2(xnod*, int, int)':
game.cpp:50:9: error: 'gcd' was not declared in this scope; did you mean 'std::gcd'?
50 | return gcd(query2(node->l, tl, tr), query2(node->r, tl, tr));
| ^~~
| std::gcd
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:84,
from game.cpp:2:
/usr/include/c++/10/numeric:131:5: note: 'std::gcd' declared here
131 | gcd(_Mn __m, _Nn __n)
| ^~~
game.cpp: In function 'void update1(ynod*, int, int, int, int, ll)':
game.cpp:66:9: error: 'gcd' was not declared in this scope; did you mean 'std::gcd'?
66 | ll v = gcd(node->l ? query2(&node->l->xst, vy, vy) : 0,node->r ? query2(&node->r->xst, vy, vy) : 0);
| ^~~
| std::gcd
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:84,
from game.cpp:2:
/usr/include/c++/10/numeric:131:5: note: 'std::gcd' declared here
131 | gcd(_Mn __m, _Nn __n)
| ^~~
game.cpp: In function 'll query1(ynod*, int, int, int, int, int, int)':
game.cpp:79:69: error: 'struct ynod' has no member named 'right'
79 | return gcd(query1(node->l, tr, m, vxl, vyl, vxr, vyr),query1(node->right, m + 1, tr, vxl, vyl,vxr,vyr));
| ^~~~~
game.cpp:79:9: error: 'gcd' was not declared in this scope; did you mean 'std::gcd'?
79 | return gcd(query1(node->l, tr, m, vxl, vyl, vxr, vyr),query1(node->right, m + 1, tr, vxl, vyl,vxr,vyr));
| ^~~
| std::gcd
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:84,
from game.cpp:2:
/usr/include/c++/10/numeric:131:5: note: 'std::gcd' declared here
131 | gcd(_Mn __m, _Nn __n)
| ^~~