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;
/*struct SegmentTree{
struct Node{
int64_t val;
Node *lc, *rc;
Node() : val(0), lc(0), rc(0) {}
};
vector<Node> tree;
Node* new_node(){
tree.emplace_back();
return &tree.back();
}
Node *root;
int L, R;
void init(int _L, int _R){
this->L = _L;
this->R = _R;
root = new_node();
}
void update(int idx, int64_t val, Node* &node, int l, int r){
if(r - l == 1){
if(!node) node = new_node();
node->val = val;
return;
}
int mid = (l + r) >> 1;
if(idx < mid) update(idx, val, node->lc, l, mid);
else update(idx, val, node->rc, mid, r);
node->val = __gcd((node->lc ? node->lc->val : 0), (node->rc ? node->rc->val : 0));
}
int64_t query(int l, int r, Node* &node, int lx, int rx){
if(r <= lx || l >= rx || !node)
return 0;
if(l >= lx && r <= rx)
return node->val;
int mid = (lx + rx) >> 1;
return __gcd(query(l, r, node->lc, lx, mid), query(l, r, node->rc, mid, rx));
}
void update(int idx, int64_t val){
update(idx, val, root, L, R);
}
int64_t query(int l, int r){
return query(l, r, root, L, R);
}
};*/
struct SegmentTree{
vector<int64_t> st;
int sz = 1;
void init(int n){
while(sz < n)
sz <<= 1;
st.resize(2*sz, 0);
}
void update(int i, int64_t v, int x, int lx, int rx){
if(rx - lx == 1){
st[x] = v;
return;
}
int mid = (lx + rx) >> 1;
if(mid > i)
update(i, v, 2*x+1, lx, mid);
else
update(i, v, 2*x+2, mid, rx);
st[x] = __gcd(st[2*x+1], st[2*x+2]);
}
void update(int i, int64_t v){
update(i, v, 0, 0, sz);
}
int64_t query(int l, int r, int x, int lx, int rx){
if(lx >= r || rx <= l)
return 0;
if(lx >= l && rx <= r)
return st[x];
int mid = (lx + rx) >> 1;
return __gcd(query(l, r, 2*x+1, lx, mid), query(l, r, 2*x+2, mid, rx));
}
int64_t query(int l, int r){
return query(l, r, 0, 0, sz);
}
};
vector<SegmentTree> T;
void init(int R, int C) {
T.resize(R);
for(int i = 0; i < R; i++){
T[i].init(C);
}
}
void update(int P, int Q, long long K) {
T[P].update(Q, K);
}
long long calculate(int P, int Q, int U, int V) {
int64_t res = 0;
for(int i = P; i <= U; i++){
res = __gcd(res, T[i].query(Q, V+1));
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |