# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
13367 |
2015-02-13T17:51:24 Z |
dohyun0324 |
Game (IOI13_game) |
C++ |
|
0 ms |
1248 KB |
#include<stdio.h>
#include "game.h"
typedef long long ll;
int n,m,x1,y1,x2,y2,k;
long long gcd2(ll X, ll Y) {
if(X==0) return Y; if(Y==0) return X;
ll tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
struct data
{
int rs,re;
data *l,*r;
data(){}
data(int s,int e):rs(s),re(e){
l=r=NULL;
}
void update3(int rx,int ry)
{
if(rx==ry){start2.update2(1,m); return;}
int mid=(rx+ry)/2;
if(x1<=mid)
{
if(l==NULL) l=new data(rx,mid);
l->update3(rx,mid);
}
else
{
if(r==NULL) r=new data(mid+1,ry);
r->update3(mid+1,ry);
}
start2.update2(1,m);
}
ll query(int rx,int ry)
{
int mid=(rx+ry)/2;
if(x1<=rx && ry<=y1) return start2.query2(1,m);
if(x1>ry || y1<rx) return 0;
if(l==NULL) l=new data(rx,mid);
if(r==NULL) r=new data(mid+1,ry);
return gcd2(l->query(rx,mid),r->query(mid+1,ry));
}
struct data2
{
int cs,ce; ll val;
data2 *l,*r;
data2(){}
data2(int s,int e,int v):cs(s),ce(e),val(v){
s=1; e=m; v=0; l=r=NULL;
}
void update2(int cx,int cy)
{
if(cx==cy){val=k; return;}
int mid=(cx+cy)/2;
if(y1<=mid)
{
if(l==NULL) l=new data2(cx,mid,0);
l->update2(cx,mid);
}
else
{
if(r==NULL) r=new data2(mid+1,cy,0);
r->update2(mid+1,cy);
}
if(r==NULL) val=l->val;
else if(l==NULL) val=r->val;
else val=gcd2(l->val,r->val);
}
ll query2(int cx,int cy)
{
int mid=(cx+cy)/2;
if(cx>y2 || cy<x2) return 0;
if((x2<=cx && cy<=y2) || (l==NULL && r==NULL))
{
return val;
}
if(l==NULL) return r->query2(mid+1,cy);
else if(r==NULL) return l->query2(cx,mid);
return val=gcd2(l->query2(cx,mid),r->query2(mid+1,cy));
}
};
data2 start2=data2(1,m,0);
};
void init(int R, int C) {
n=R, m=C;
}
data start=data(1,n);
void update(int P, int Q, long long K) {
P++; Q++;
x1=P; y1=Q; k=K;
start.update3(1,n);
}
long long calculate(int P, int Q, int U, int V) {
P++; Q++; U++; V++;
x1=P; y1=U; x2=Q; y2=V;
return start.query(1,n);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |