#include "game.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
struct node{
ll tl, tr, val;
node *l = nullptr, *r = nullptr;
node(ll tlval, ll trval){
tl = tlval;
tr = trval;
val = 0;
};
void upd(ll idx, ll nv){
if(tl == idx && tr == idx){
val = nv;
return;
}
ll tm = (tl+tr)/2;
if(idx <= tm){
if(!l)
l = new node(tl, tm);
l->upd(idx, nv);
}
else{
if(!r)
r = new node(tm+1, tr);
r->upd(idx, nv);
}
val = 0;
if(l)
val = __gcd(val, l->val);
if(r)
val = __gcd(val, r->val);
}
ll get(ll lef, ll rig){
if(tr < lef || rig < tl)
return 0;
if(lef <= tl && tr <= rig){
return val;
}
ll xval = 0, yval = 0;
if(l)
xval = l->get(lef, rig);
if(r)
yval = r->get(lef, rig);
return __gcd(xval, yval);
}
};
ll r, c;
struct seg{
ll tl, tr;
node *val;
seg *l = nullptr, *r = nullptr;
seg(ll tval, ll rval){
tl = tval;
tr = rval;
val = new node(0, c-1);
}
seg(){}
void upd(ll xidx, ll yidx, ll nv){
val->upd(yidx, nv);
if(tl == xidx && tr == xidx){
return;
}
ll tm = (tl+tr)/2;
if(xidx <= tm){
if(!l)
l = new seg(tl, tm);
l->upd(xidx, yidx, nv);
}
else{
if(!r)
r = new seg(tm+1, tr);
r->upd(xidx, yidx, nv);
}
}
ll get(ll xl, ll xr, ll yl, ll yr){
if(tr < xl || xr < tl)
return 0;
if(xl <= tl && tr <= xr){
return val->get(yl, yr);
}
ll xval = 0, yval = 0;
if(l)
xval = l->get(xl, xr, yl, yr);
if(r)
yval = r->get(xl, xr, yl, yr);
return __gcd(xval, yval);
}
};
seg root;
void init(int R, int C) {
r = R;
c = C;
root = seg(0, r-1);
}
void update(int P, int Q, long long K) {
root.upd(P, Q, K);
}
long long calculate(int P, int Q, int U, int V) {
return root.get(P, U, Q, V);
}
Compilation message
grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
18 | int res;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |