#include "game.h"
#include <bits/stdc++.h>
using namespace std;
struct Seg
{
int l, r, p;
long long v;
Seg() : l(0), r(0), p(-1), v(0) {}
};
const int MAX=1e9;
Seg tree[222222], tree2[7777777];
int tp1=1, tp2;
long long GCD(long long a, long long b)
{
for(;b;a%=b,swap(a,b));
return a;
}
long long get_gcd2(int n1, int n2, int p, int s=0, int e=MAX)
{
int m=(s+e)>>1;
if(p==0 || n2<s || e<n1) return 0;
if(tree[p].p!=-1) return n1<=tree[p].p && tree[p].p<=n2 ? tree[p].v:0;
if(n1<=s && e<=n2) return tree2[p].v;
return GCD(get_gcd2(n1,n2,tree2[p].l,s,m),get_gcd2(n1,n2,tree2[p].r,m+1,e));
}
long long get_gcd(int x1, int x2, int y1, int y2, int p=1, int s=0, int e=MAX)
{
int m=(s+e)>>1;
if(p==0 || x2<s || e<x1) return 0;
if(x1<=s && e<=x2) return get_gcd2(y1,y2,tree[p].v);
return GCD(get_gcd(x1,x2,y1,y2,tree[p].l,s,m),get_gcd(x1,x2,y1,y2,tree[p].r,m+1,e));
}
void set_tree2(int n, long long v, int p, int s=0, int e=MAX)
{
int m=(s+e)>>1;
if(s==e) {
tree2[p].v=v;
return;
}
if(tree2[p].p!=-1) {
if(tree2[p].p==n) {
tree2[p].v=v;
return;
}
if(tree2[p].p<=m) {
tree2[tree2[p].l=++tp2].p=tree2[p].p;
tree2[tree2[p].l].v=tree2[p].v;
}
else {
tree2[tree2[p].r=++tp2].p=tree2[p].p;
tree2[tree2[p].r].v=tree2[p].v;
}
tree2[p].p=-1;
}
if(tree2[p].p==-1 && tree2[p].l==0 && tree2[p].r==0) {
tree2[p].v=v;
tree2[p].p=n;
return;
}
if(n<=m) {
if(tree2[p].l==0) tree2[p].l=++tp2;
set_tree2(n,v,tree2[p].l,s,m);
}
else {
if(tree2[p].r==0) tree2[p].r=++tp2;
set_tree2(n,v,tree2[p].r,m+1,e);
}
tree2[p].v=GCD(tree2[tree2[p].l].v,tree2[tree2[p].r].v);
}
void set_tree(int x, int y, long long v, int p=1, int s=0, int e=MAX)
{
int m=(s+e)>>1;
if(tree[p].v==0) tree[p].v=++tp2;
if(s==e) {
set_tree2(y,v,tree[p].v);
return;
}
if(x<=m) {
if(tree[p].l==0) tree[p].l=++tp1;
set_tree(x,y,v,tree[p].l,s,m);
}
else {
if(tree[p].r==0) tree[p].r=++tp1;
set_tree(x,y,v,tree[p].r,m+1,e);
}
set_tree2(y,GCD(get_gcd2(y,y,tree[tree[p].l].v),get_gcd2(y,y,tree[tree[p].r].v)),tree[p].v);
}
void init(int R, int C) {}
void update(int P, int Q, long long K) {set_tree(P,Q,K);}
long long calculate(int P, int Q, int U, int V) {return get_gcd(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]
int res;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
152 ms |
188280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
146 ms |
188120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
139 ms |
188112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
136 ms |
188116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
155 ms |
188152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |