# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
898179 | Faisal_Saqib | 게임 (IOI13_game) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node
{
int s, e;
ll gc;
node *lc, *rc;
node(int S, int E) {
s = S, e = E, gc = 0;
}
void update(int p, ll K)
{
if(p < s || e <= p) return;
if(e - s == 1) {
gc = K;
return;
}
if(lc == NULL) {
int mid = (s + e) / 2;
lc = new node(s, mid);
rc = new node(mid, e);
}
lc -> update(p, K);
rc -> update(p, K);
gc = gcd(lc -> gc, rc -> gc);
}
ll get(int l, int r)
{
if(r <= s || e <= l) return 0;
if(l <= s && e <= r) return gc;
if(lc == NULL) return 0;
return gcd(lc -> get(l, r), rc -> get(l, r));
}
};
int sz;
struct Segnode
{
int s, e;
node *tree;
Segnode *lc, *rc;
Segnode(int S, int E) {
s = S, e = E;
tree = new node(0, sz);
}
void update(int p, int p2, ll K)
{
if(p < s || e <= p) return;
if(e - s == 1){
tree->update(p2, K);
return;
}
if(lc == NULL) {
int mid = (s + e) / 2;
lc = new Segnode(s, mid);
rc = new Segnode(mid, e);
}
lc -> update(p, p2, K);
rc -> update(p, p2, K);
ll g1 = lc -> tree -> get(p2, p2 + 1), g2 = rc -> tree -> get(p2, p2 + 1);
tree -> update(p2, gcd(g1, g2));
}
ll get(int lx, int rx, int ly, int ry)
{
if(rx <= s || e <= lx) return 0;
if(lx <= s && e <= rx)
return tree->get(ly, ry);
if(lc == NULL) return 0;
return gcd(lc -> get(lx, rx, ly, ry),
rc -> get(lx, rx, ly, ry));
}
};
Segnode* tree;
void init(int R, int C)
{
sz = C;
tree = new Segnode(0, R);
}
void update(int p, int q, ll K)
{
tree->update(p, q, K);
}
ll calculate(int lx, int ly, int rx, int ry)
{
rx ++ , ry++;
return tree->get(lx, rx, ly, ry);
}