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 "game.h"
#include <bits/stdc++.h>
using namespace std;
int _R, _C;
struct node2
{
long long v;
node2 *L, *R;
node2()
{
v = 0;
L = R = NULL;
}
static void extend()
{
if(!L)
{
L = new node2();
R = new node2();
}
}
};
struct node1
{
node2 *now;
node1 *L, *R;
node1()
{
now = new node2();
L = R = NULL;
}
static void extend()
{
if(!L)
{
L = new node1();
R = new node1();
}
}
};
node1 *root;
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;
}
static void init(int R, int C) {
_R = R, _C = C;
root = new node1();
}
static void update2(node2 *seg, int l, int r, int p, long long v) {
seg->extend();
if(l == r) return static void(seg->v = v);
int mid = (l+r)>>1;
if(p <= mid) update2(seg->L, l, mid, p, v);
else update2(seg->R, mid+1, r, p, v);
seg->v = gcd2(seg->L->v, seg->R->v);
}
static void push_seg(node2 *seg, node2 *L, node2 *R, int l, int r, int p) {
seg->extend();
L->extend();
R->extend();
if(l == r) return static void(seg->v = gcd2(L->v, R->v));
int mid = (l+r)>>1;
if(p <= mid) push_seg(seg->L, L->L, R->L, l, mid, p);
else push_seg(seg->R, L->R, R->R, mid+1, r, p);
seg->v = gcd2(L->v, R->v);
}
static void update1(node1 *seg, int l, int r, int p, int _p, long long v) {
seg->extend();
if(l == r) return static void(update2(seg->now, 1, _C, _p, v));
int mid = (l+r)>>1;
if(p <= mid) update1(seg->L, l, mid, p, _p, v);
else update1(seg->R, mid+1, r, p, _p, v);
push_seg(seg->now, seg->L->now, seg->R->now, 1, _C, _p);
}
static void update(int P, int Q, long long K) {
P++, Q++;
update1(root, 1, _R, P, Q, K);
}
long long query2(node2 *seg, int l, int r, int a, int b) {
if(!seg || r < a || b < l) return 0;
if(a <= l && r <= b) return seg->v;
int mid = (l+r)>>1;
return gcd2(query2(seg->L, l, mid, a, b), query2(seg->R, mid+1, r, a, b));
}
long long query1(node1 *seg, int l, int r, int a, int b, int _a, int _b) {
if(!seg || r < a || b < l) return 0;
if(a <= l && r <= b) return query2(seg->now, 1, _C, _a, _b);
int mid = (l+r)>>1;
return gcd2(query1(seg->L, l, mid, a, b, _a, _b), query1(seg->R, mid+1, r, a, b, _a, _b));
}
long long calculate(int P, int Q, int U, int V) {
P++, Q++, U++, V++;
return query1(root, 1, _R, P, U, Q, V);
}
Compilation message (stderr)
grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
int res;
^~~
game.cpp: In static member function 'static void node2::extend()':
game.cpp:18:13: error: invalid use of member 'node2::L' in static member function
if(!L)
^
game.cpp:10:12: note: declared here
node2 *L, *R;
^
game.cpp:20:13: error: invalid use of member 'node2::L' in static member function
L = new node2();
^
game.cpp:10:12: note: declared here
node2 *L, *R;
^
game.cpp:21:13: error: invalid use of member 'node2::R' in static member function
R = new node2();
^
game.cpp:10:16: note: declared here
node2 *L, *R;
^
game.cpp: In static member function 'static void node1::extend()':
game.cpp:37:13: error: invalid use of member 'node1::L' in static member function
if(!L)
^
game.cpp:29:12: note: declared here
node1 *L, *R;
^
game.cpp:39:13: error: invalid use of member 'node1::L' in static member function
L = new node1();
^
game.cpp:29:12: note: declared here
node1 *L, *R;
^
game.cpp:40:13: error: invalid use of member 'node1::R' in static member function
R = new node1();
^
game.cpp:29:16: note: declared here
node1 *L, *R;
^
game.cpp: In function 'void init(int, int)':
game.cpp:57:13: error: 'void init(int, int)' was declared 'extern' and later 'static' [-fpermissive]
static void init(int R, int C) {
^~~~
In file included from game.cpp:1:0:
game.h:8:6: note: previous declaration of 'void init(int, int)'
void init(int R, int C);
^~~~
game.cpp: In function 'void update2(node2*, int, int, int, long long int)':
game.cpp:64:23: error: expected primary-expression before 'static'
if(l == r) return static void(seg->v = v);
^~~~~~
game.cpp:64:23: error: return-statement with a value, in function returning 'void' [-fpermissive]
game.cpp:64:23: error: expected ';' before 'static'
game.cpp:64:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(l == r) return static void(seg->v = v);
^~
game.cpp:64:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(l == r) return static void(seg->v = v);
^~~~~~
game.cpp:64:23: error: expected primary-expression before 'static'
game.cpp: In function 'void push_seg(node2*, node2*, node2*, int, int, int)':
game.cpp:75:23: error: expected primary-expression before 'static'
if(l == r) return static void(seg->v = gcd2(L->v, R->v));
^~~~~~
game.cpp:75:23: error: return-statement with a value, in function returning 'void' [-fpermissive]
game.cpp:75:23: error: expected ';' before 'static'
game.cpp:75:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(l == r) return static void(seg->v = gcd2(L->v, R->v));
^~
game.cpp:75:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(l == r) return static void(seg->v = gcd2(L->v, R->v));
^~~~~~
game.cpp:75:23: error: expected primary-expression before 'static'
game.cpp: In function 'void update1(node1*, int, int, int, int, long long int)':
game.cpp:84:23: error: expected primary-expression before 'static'
if(l == r) return static void(update2(seg->now, 1, _C, _p, v));
^~~~~~
game.cpp:84:23: error: return-statement with a value, in function returning 'void' [-fpermissive]
game.cpp:84:23: error: expected ';' before 'static'
game.cpp:84:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(l == r) return static void(update2(seg->now, 1, _C, _p, v));
^~
game.cpp:84:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(l == r) return static void(update2(seg->now, 1, _C, _p, v));
^~~~~~
game.cpp:84:23: error: expected primary-expression before 'static'
game.cpp: In function 'void update(int, int, long long int)':
game.cpp:91:13: error: 'void update(int, int, long long int)' was declared 'extern' and later 'static' [-fpermissive]
static void update(int P, int Q, long long K) {
^~~~~~
In file included from game.cpp:1:0:
game.h:9:6: note: previous declaration of 'void update(int, int, long long int)'
void update(int P, int Q, long long K);
^~~~~~