# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
71032 |
2018-08-24T03:22:43 Z |
KLPP |
게임 (IOI13_game) |
C++14 |
|
0 ms |
0 KB |
//#include "game.h"
#include<iostream>
#include<stdio.h>
using namespace std;
typedef long long lld;
long long gcd2(long long X, long long Y) {
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
struct node1{
node1 *left, *right;
int l, r;
lld vl;
} typedef node1;
struct node2{
node2 *left,*right;
node1 *segtree;
int l,r;
}typedef node2;
void build(node1 *n,int l,int r){
n->l=l;
n->r=r;
n->vl=0;
}
void extend(node1 *v){
if(v->l==v->r)return;
if(v->left==NULL){
v->left=new node1();
v->right=new node1();
int mid=(v->l+v->r)/2;
build(v->left,v->l,mid);
build(v->right,mid+1,v->r);
}
}
void update(node1 *v,int pos, lld val){
if(v->l>pos || v->r<pos)return;
if(v->l==pos && v->r==pos){
v->vl=val;
return;
}
extend(v);
update(v->left,pos,val);
update(v->right,pos,val);
v->vl=gcd2(v->left->vl,v->right->vl);
}
lld query(node1 *v, int l, int r){
if(v==NULL)return 0;
if(v->l>r || v->r<l){
return 0;
}
if(l<=v->l && v->r<=r){
return v->vl;
}
return gcd2(query(v->left,l,r),query(v->right,l,r));
}
void build2(node2 *n,int l1, int r1,int l2, int r2){
n->l=l1;
n->r=r1;
n->segtree=new node1();
build(n->segtree,l2,r2);
}
void extend2(node2 *v){
if(v->l==v->r)return;
if(v->left==NULL){
v->left=new node2();
v->right=new node2();
int mid=(v->l+v->r)/2;
build2(v->left,v->l,mid,v->segtree->l,v->segtree->r);
build2(v->right,mid+1,v->r,v->segtree->l,v->segtree->r);
}
}
void update2(node2 *v,int x, int y,lld val){//x<R,y<C
//cout<<v->l<<" "<<v->r<<endl;
if(v->l>x || v->r<x)return;
if(v->l==x && v->r==x){
update(v->segtree,y,val);
return;
}
extend2(v);
update2(v->left,x,y,val);
update2(v->right,x,y,val);
lld v1=query(v->left->segtree,y,y);
v1=gcd2(v1,query(v->right->segtree,y,y));
update(v->segtree,y,v1);
}
lld query2(node2 *v,int x1, int y1, int x2, int y2){
if(v==NULL)return 0;
if(v->l>x2 || v->r<x1){
return 0;
}
if(x1<=v->l && v->r<=x2){
return query(v->segtree,y1,y2);
}
return gcd2(query2(v->left,x1,y1,x2,y2),query2(v->right,x1,y1,x2,y2));
}
node2 *tree;
void init(int R, int C) {tree=new node2();
build2(tree,0,R-1,0,C-1);
}
void update(int P, int Q, long long K) {
update2(tree,P,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
return query2(tree,P,Q,U,V);
}
/*int main(){
int R,C,N;
cin>>R>>C>>N;init(R,C);
while(N--){
int up;
cin>>up;
if(up==1){
int p,q;
lld val;
cin>>p>>q>>val;
update(p,q,val);
}else{
int p,q,u,v;
cin>>p>>q>>u>>v;
cout<<calculate(p,q,u,v)<<endl;
}
}
return 0;
}*/
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;
^~~
/tmp/ccHWBuUb.o: In function `main':
grader.c:(.text.startup+0x5d): undefined reference to `init'
grader.c:(.text.startup+0xb8): undefined reference to `calculate'
grader.c:(.text.startup+0x122): undefined reference to `update'
collect2: error: ld returned 1 exit status