이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "game.h"
#include <bits/stdc++.h>
#define N 4000005
using namespace std;
int R,C;
struct node1{
long long val;
int l,r;
int lc,rc;
node1():lc(0),rc(0),val(0){
}
}t1[N];
int cnt1 = 1;
struct SegTree{
int root;
SegTree():root(0){
}
void upd(int v,int pos,long long val){
if(t1[v].l == t1[v].r){
t1[v].val = val;
return;
}
if(t1[v].lc != 0 && t1[t1[v].lc].l <= pos && pos <= t1[t1[v].lc].r){
upd(t1[v].lc,pos,val);
t1[v].val = __gcd(t1[t1[v].lc].val,t1[t1[v].rc].val);
return;
}
if(t1[v].rc != 0 && t1[t1[v].rc].l <= pos && pos <= t1[t1[v].rc].r){
upd(t1[v].rc,pos,val);
t1[v].val = __gcd(t1[t1[v].lc].val,t1[t1[v].rc].val);
return;
}
int tm = (t1[v].l + t1[v].r)/2;
if(t1[v].lc == 0 && pos <= tm){
t1[v].lc = cnt1++;
t1[t1[v].lc].val = val;
t1[t1[v].lc].l = pos;
t1[t1[v].lc].r = pos;
t1[v].val = __gcd(t1[t1[v].lc].val,t1[t1[v].rc].val);
return;
}
if(t1[v].rc == 0 && pos > tm){
t1[v].rc = cnt1++;
t1[t1[v].rc].val = val;
t1[t1[v].rc].l = pos;
t1[t1[v].rc].r = pos;
t1[v].val = __gcd(t1[t1[v].lc].val,t1[t1[v].rc].val);
return;
}
if(pos <= tm){
int tmp = t1[v].lc;
t1[v].lc = cnt1++;
t1[t1[v].lc].l = t1[v].l;
t1[t1[v].lc].r = tm;
while(1){
int tmm = (t1[t1[v].lc].l + t1[t1[v].lc].r)/2;
if(t1[tmp].r <= tmm && pos <= tmm){
t1[t1[v].lc].r = tmm;
continue;
}
if(t1[tmp].l > tmm && pos > tmm){
t1[t1[v].lc].l = tmm + 1;
continue;
}
break;
}
if(pos < t1[tmp].l){
t1[t1[v].lc].lc = cnt1++;
t1[t1[v].lc].rc = tmp;
t1[t1[t1[v].lc].lc].val = val;
t1[t1[t1[v].lc].lc].l = pos;
t1[t1[t1[v].lc].lc].r = pos;
}
else{
t1[t1[v].lc].lc = tmp;
t1[t1[v].lc].rc = cnt1++;
t1[t1[t1[v].lc].rc].val = val;
t1[t1[t1[v].lc].rc].l = pos;
t1[t1[t1[v].lc].rc].r = pos;
}
t1[t1[v].lc].val = __gcd(t1[t1[t1[v].lc].lc].val,t1[t1[t1[v].lc].rc].val);
}
else{
int tmp = t1[v].rc;
t1[v].rc = cnt1++;
t1[t1[v].rc].l = tm+1;
t1[t1[v].rc].r = t1[v].r;
while(1){
int tmm = (t1[t1[v].rc].l + t1[t1[v].rc].r)/2;
if(t1[tmp].r <= tmm && pos <= tmm){
t1[t1[v].rc].r = tmm;
continue;
}
if(t1[tmp].l > tmm && pos > tmm){
t1[t1[v].rc].l = tmm + 1;
continue;
}
break;
}
if(pos < t1[tmp].l){
t1[t1[v].rc].lc = cnt1++;
t1[t1[v].rc].rc = tmp;
t1[t1[t1[v].rc].lc].val = val;
t1[t1[t1[v].rc].lc].l = pos;
t1[t1[t1[v].rc].lc].r = pos;
}
else{
t1[t1[v].rc].lc = tmp;
t1[t1[v].rc].rc = cnt1++;
t1[t1[t1[v].rc].rc].val = val;
t1[t1[t1[v].rc].rc].l = pos;
t1[t1[t1[v].rc].rc].r = pos;
}
t1[t1[v].rc].val = __gcd(t1[t1[t1[v].rc].lc].val,t1[t1[t1[v].rc].rc].val);
}
t1[v].val = __gcd(t1[t1[v].lc].val,t1[t1[v].rc].val);
}
long long get(int v,int l,int r){
//cout << v << ' ' << l << ' ' << r << endl;
if(v == 0)
return 0;
if(t1[v].r < l || r < t1[v].l)
return 0;
if(l <= t1[v].l && t1[v].r <= r){
return t1[v].val;
}
return __gcd(get(t1[v].lc,l,r),get(t1[v].rc,l,r));
}
void upd(int pos,long long val){
if(root == 0){
root = cnt1++;
t1[root].l = 0;
t1[root].r = C-1;
}
upd(root,pos,val);
}
long long get(int l,int r){
//cout << "HEY" << endl;
return get(root,l,r);
}
};
struct Node2{
int lc,rc;
SegTree t;
Node2():lc(0),rc(0){
}
}t2[N];
int cnt2 = 1;
struct SegTree2D{
int root;
SegTree2D():root(0){}
void upd(int v,int tl,int tr,int pos1,int pos2,long long val){
t2[v].t.upd(pos2,val);
if(tl == tr){
return;
}
int tm = (tl + tr)/2;
if(pos1 <= tm){
if(t2[v].lc == 0)
t2[v].lc = cnt2++;
upd(t2[v].lc,tl,tm,pos1,pos2,val);
}
else{
if(t2[v].rc == 0)
t2[v].rc = cnt2++;
upd(t2[v].rc,tm+1,tr,pos1,pos2,val);
}
}
long long get(int v,int tl,int tr,int l1,int r1,int l2,int r2){
//cout << v << ' ' << tl << ' ' << tr << endl;
if(v == 0)
return 0;
if(tr < l1 || r1 < tl){
return 0;
}
if(l1 <= tl && tr <= r1){
return t2[v].t.get(l2,r2);
}
int tm = (tl + tr)/2;
return __gcd(get(t2[v].lc,tl,tm,l1,r1,l2,r2),get(t2[v].rc,tm+1,tr,l1,r1,l2,r2));
}
void upd(int pos1,int pos2,long long val){
if(root == 0){
root = cnt2++;
}
upd(root,0,R-1,pos1,pos2,val);
}
long long get(int l1,int r1,int l2,int r2){
return get(root, 0, R-1, l1, r1, l2, r2);
}
}tree;
void init(int r, int c) {
R = r;
C = c;
}
void update(int P, int Q, long long K) {
tree.upd(P,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
return tree.get(P,U,Q,V);
}
컴파일 시 표준 에러 (stderr) 메시지
game.cpp: In constructor 'node1::node1()':
game.cpp:10:12: warning: 'node1::rc' will be initialized after [-Wreorder]
10 | int lc,rc;
| ^~
game.cpp:8:15: warning: 'long long int node1::val' [-Wreorder]
8 | long long val;
| ^~~
game.cpp:11:5: warning: when initialized here [-Wreorder]
11 | node1():lc(0),rc(0),val(0){
| ^~~~~
# | 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... |