This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "game.h"
#define MAXN 25007
using namespace std;
const int maxs=1e9;
unordered_map<int,int> mp;
struct node{
int l,r;
long long val;
};
int num;
node tree[400*MAXN];
struct ST{
int root;
void init(){
num++;
root=num;
}
void addnode(){
num++;
}
void update(int v,int l,int r,int pos,long long val){
if(l==r){
tree[v].val=val;
}else{
int tt=(l+r)/2;
if(pos<=tt){
if(tree[v].l==0){
addnode(); tree[v].l=num;
}
update(tree[v].l,l,tt,pos,val);
}else{
if(tree[v].r==0){
addnode(); tree[v].r=num;
}
update(tree[v].r,tt+1,r,pos,val);
}
tree[v].val=__gcd(tree[tree[v].l].val,tree[tree[v].r].val);
}
}
long long getgcd(int v,int l,int r,int ll,int rr){
if(v==0 or ll>rr)return 0;
if(l==ll and r==rr){
return tree[v].val;
}else{
int tt=(l+r)/2;
return __gcd( getgcd(tree[v].l,l,tt,ll,min(tt,rr)) , getgcd(tree[v].r,tt+1,r,max(tt+1,ll),rr) );
}
}
void upd(int pos,long long val){
update(root,1,maxs,pos,val);
}
long long query(int l,int r){
return getgcd(root,1,maxs,l,r);
}
};
int last,currid;
ST col[MAXN];
struct ST2D{
struct node{
int l,r;
ST t;
};
node tree[35*MAXN];
vector< pair<int,long long> > w[35*MAXN];
int num;
void init(){
tree[1].t.init();
num=1;
}
void addnode(){
num++;
tree[num].t.init();
}
void update(int v,int l,int r,int posx,int posy,long long val){
if(l==r){
if(w[v].empty()){
w[v].push_back({posy,val});
return;
}
for(int i=0;i<w[v].size();i++){
if(w[v][i].first==posy)w[v][i].second=val;
else if(i==w[v].size()-1){
w[v].push_back({posy,val});
break;
}
}
}else{
int tt=(l+r)/2;
if(posx<=tt){
if(tree[v].l==0){
addnode(); tree[v].l=num;
}
update(tree[v].l,l,tt,posx,posy,val);
}else{
if(tree[v].r==0){
addnode(); tree[v].r=num;
}
update(tree[v].r,tt+1,r,posx,posy,val);
}
long long newval = col[currid].query(l,r);
tree[v].t.upd(posy,newval);
}
}
long long getgcd(int v,int l,int r,int lx,int rx,int ly,int ry){
if(v==0 or lx>rx)return 0;
if(l==lx and r==rx){
if(l!=r)return tree[v].t.query(ly,ry);
else{
long long res=0;
for(int i=0;i<w[v].size();i++){
if(w[v][i].first<ly or w[v][i].first>ry)continue;
res=__gcd(res,w[v][i].second);
}
return res;
}
}else{
int tt=(l+r)/2;
return __gcd( getgcd(tree[v].l,l,tt,lx,min(tt,rx),ly,ry) , getgcd(tree[v].r,tt+1,r,max(tt+1,lx),rx,ly,ry) );
}
}
void upd(int x,int y,long long val){
update(1,1,maxs,x,y,val);
}
long long query(int a,int b,int c,int d){
return getgcd(1,1,maxs,a,c,b,d);
}
}seg;
void init(int R, int C) {
seg.init();
}
void update(int P, int Q, long long K) {
P++; Q++;
if(mp[Q]==0){
last++; mp[Q]=last;
col[last].init();
}
currid=mp[Q];
col[currid].upd(P,K);
seg.upd(P,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
P++; Q++; U++; V++;
return seg.query(P,Q,U,V);
}
/*int main(){
init(10,10);
update(0,0,20);
update(0,2,15);
update(1,1,12);
cout<<calculate(0,0,0,2)<<"\n";
cout<<calculate(0,0,1,1)<<"\n";
update(0,1,6);
update(1,1,14);
cout<<calculate(0,0,0,2)<<"\n";
cout<<calculate(0,0,1,1)<<"\n";
return 0;
}*/
Compilation message (stderr)
game.cpp: In member function 'void ST2D::update(int, int, int, int, int, long long int)':
game.cpp:104:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for(int i=0;i<w[v].size();i++){
| ~^~~~~~~~~~~~
game.cpp:106:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | else if(i==w[v].size()-1){
| ~^~~~~~~~~~~~~~~
game.cpp: In member function 'long long int ST2D::getgcd(int, int, int, int, int, int, int)':
game.cpp:139:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
139 | for(int i=0;i<w[v].size();i++){
| ~^~~~~~~~~~~~
# | 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... |