#include "game.h"
#include<algorithm>
#include<vector>
int a,b,X,t;
struct A{
int s,e,left,right,ynum;
};
struct B{
int s,e,left,right;long long val;
};
std::vector<A>xTree;
yTree;
long long gcd2(long long xx,long long yy){
if(yy==0)return xx;
return gcd2(yy,xx%yy);
}
void yup(int num,int num1,int num2,int xco,int yco,long long v)
{
int s1=yTree[num].s,e1=yTree[num].e;
if(s1==e1){
if(num1==-1&&num2==-1)yTree[num].val=v;
else yTree[num].val=gcd2(num1==-1?0:yTree[num1].val,num2==-1?0:yTree[num2].val);
return ;
}
if((s1+e1)/2>=yco)
{
if(yTree[num].left==-1)
{
yTree[num].left=yTree.size();
yTree.push_back({s1,(s1+e1)/2,-1,-1,0});
}
if(num1>=0)num1=yTree[num1].left;
if(num2>=0)num2=yTree[num2].left;
yup(yTree[num].left,num1,num2,xco,yco,v);
}
else
{
if(yTree[num].right==-1)
{
yTree[num].right=yTree.size();
yTree.push_back({(s1+e1)/2+1,e1,-1,-1,0});
}
if(num1>=0)num1=yTree[num1].right;
if(num2>=0)num2=yTree[num2].right;
yup(yTree[num].right,num1,num2,xco,yco,v);
}
yTree[num].val=gcd2(yTree[num].left>=0?yTree[yTree[num].left].val:0,yTree[num].right>=0?yTree[yTree[num].right].val:0);
}
void xup(int num,int xco,int yco,long long v)
{
if(xTree[num].ynum==-1)
{
xTree[num].ynum=yTree.size();
yTree.push_back({0,X,-1,-1,0});
}
if(xTree[num].s==xTree[num].e)
{
yup(xTree[num].ynum,-1,-1,xco,yco,v);
return ;
}
int s1=xTree[num].s,e1=xTree[num].e;
if((s1+e1)/2>=xco)
{
if(xTree[num].left==-1)
{
xTree[num].left=xTree.size();
xTree.push_back({s1,(s1+e1)/2,-1,-1,-1});
}
xup(xTree[num].left,xco,yco,v);
}
else
{
if(xTree[num].right==-1)
{
xTree[num].right=xTree.size();
xTree.push_back({(s1+e1)/2+1,e1,-1,-1,-1});
}
xup(xTree[num].right,xco,yco,v);
}
yup(xTree[num].ynum,xTree[num].left==-1?-1:xTree[xTree[num].left].ynum,xTree[num].right==-1?-1:xTree[xTree[num].right].ynum,xco,yco,v);
}
long long yans(int num,int px,int qx,int py,int qy)
{
if(yTree[num].s>qy||yTree[num].e<py)return 0ll;
if(py<=yTree[num].s&&yTree[num].e<=qy)return yTree[num].val;
long long l=0,r=0;
if(yTree[num].left>=0)l=yans(yTree[num].left,px,qx,py,qy);
if(yTree[num].right>=0)r=yans(yTree[num].right,px,qx,py,qy);
return gcd2(l,r);
}
long long xans(int num,int px,int qx,int py,int qy)
{
if(xTree[num].s>qx||xTree[num].e<px)return 0ll;
if(px<=xTree[num].s&&xTree[num].e<=qx)
{
if(xTree[num].ynum>=0)return yans(xTree[num].ynum,px,qx,py,qy);
else return 0ll;
}
long long l=0,r=0;
if(xTree[num].left>=0)l=xans(xTree[num].left,px,qx,py,qy);
if(xTree[num].right>=0)r=xans(xTree[num].right,px,qx,py,qy);
return gcd2(l,r);
}
void init(int R, int C)
{
a=R;b=C;X=1e9;
xTree.push_back({0,X,-1,-1,0});
yTree.push_back({0,X,-1,-1,0});
}
void update(int P, int Q, long long K)
{
xup(0,P,Q,K);
}
long long calculate (int P, int Q, int U, int V)
{
return xans(0,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;
^
game.cpp:12:1: error: ‘yTree’ does not name a type
yTree;
^
game.cpp: In function ‘void yup(int, int, int, int, int, long long int)’:
game.cpp:19:12: error: ‘yTree’ was not declared in this scope
int s1=yTree[num].s,e1=yTree[num].e;
^
game.cpp:20:12: error: ‘e1’ was not declared in this scope
if(s1==e1){
^
game.cpp:25:12: error: ‘e1’ was not declared in this scope
if((s1+e1)/2>=yco)
^
game.cpp:30:29: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
yTree.push_back({s1,(s1+e1)/2,-1,-1,0});
^
game.cpp:41:29: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
yTree.push_back({(s1+e1)/2+1,e1,-1,-1,0});
^
game.cpp: In function ‘void xup(int, int, int, long long int)’:
game.cpp:53:25: error: ‘yTree’ was not declared in this scope
xTree[num].ynum=yTree.size();
^
game.cpp:54:25: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
yTree.push_back({0,X,-1,-1,0});
^
game.cpp:67:29: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
xTree.push_back({s1,(s1+e1)/2,-1,-1,-1});
^
game.cpp:67:52: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
xTree.push_back({s1,(s1+e1)/2,-1,-1,-1});
^
game.cpp:76:29: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
xTree.push_back({(s1+e1)/2+1,e1,-1,-1,-1});
^
game.cpp:76:54: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
xTree.push_back({(s1+e1)/2+1,e1,-1,-1,-1});
^
game.cpp: In function ‘long long int yans(int, int, int, int, int)’:
game.cpp:84:8: error: ‘yTree’ was not declared in this scope
if(yTree[num].s>qy||yTree[num].e<py)return 0ll;
^
game.cpp:85:12: error: ‘yTree’ was not declared in this scope
if(py<=yTree[num].s&&yTree[num].e<=qy)return yTree[num].val;
^
game.cpp:87:8: error: ‘yTree’ was not declared in this scope
if(yTree[num].left>=0)l=yans(yTree[num].left,px,qx,py,qy);
^
game.cpp:88:8: error: ‘yTree’ was not declared in this scope
if(yTree[num].right>=0)r=yans(yTree[num].right,px,qx,py,qy);
^
game.cpp: In function ‘void init(int, int)’:
game.cpp:107:21: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
xTree.push_back({0,X,-1,-1,0});
^
game.cpp:107:34: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
xTree.push_back({0,X,-1,-1,0});
^
game.cpp:108:5: error: ‘yTree’ was not declared in this scope
yTree.push_back({0,X,-1,-1,0});
^
game.cpp:108:21: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
yTree.push_back({0,X,-1,-1,0});
^