# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
140222 |
2019-08-02T10:12:14 Z |
amiratou |
Game (IOI13_game) |
C++14 |
|
4 ms |
504 KB |
#include "game.h"
#include <bits/stdc++.h>
#define ll long long
ll st[8005][8005],st2[45][400005],n,m;
using namespace std;
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;
}
void update_y2(int ny,int ly,int ry,int nx,int lx,int rx,int y,ll val){
if(ly>y||ry<y)
return ;
if(ly==ry){
if(lx==rx)st2[nx][ny]=val;
else st2[nx][ny]=gcd2(st2[nx*2][ny],st2[nx*2+1][ny]);
return ;
}
int med=(ly+ry)>>1;
update_y2(ny*2,ly,med,nx,lx,rx,y,val);
update_y2(ny*2+1,med+1,ry,nx,lx,rx,y,val);
st2[nx][ny]=gcd2(st2[nx][ny*2],st2[nx][ny*2+1]);
}
void update_x2(int nx,int lx,int rx,int x,int y,ll val){
if(lx>x||rx<x)
return ;
if(lx!=rx){
int med=(lx+rx)>>1;
update_x2(nx*2,lx,med,x,y,val);
update_x2(nx*2+1,med+1,rx,x,y,val);
}
update_y2(1,0,m-1,nx,lx,rx,y,val);
}
void update_y(int ny,int ly,int ry,int nx,int lx,int rx,int y,ll val){
if(ly>y||ry<y)
return ;
if(ly==ry){
if(lx==rx)st[nx][ny]=val;
else st[nx][ny]=gcd2(st[nx*2][ny],st[nx*2+1][ny]);
return ;
}
int med=(ly+ry)>>1;
update_y(ny*2,ly,med,nx,lx,rx,y,val);
update_y(ny*2+1,med+1,ry,nx,lx,rx,y,val);
st[nx][ny]=gcd2(st[nx][ny*2],st[nx][ny*2+1]);
}
void update_x(int nx,int lx,int rx,int x,int y,ll val){
if(lx>x||rx<x)
return ;
if(lx!=rx){
int med=(lx+rx)>>1;
update_x(nx*2,lx,med,x,y,val);
update_x(nx*2+1,med+1,rx,x,y,val);
}
update_y(1,0,m-1,nx,lx,rx,y,val);
}
int query_y2(int ny,int ly,int ry,int nx,int y1,int y2){
if(ly>y2||ry<y1)
return 0;
if(ly>=y1&&ry<=y2)
return st2[nx][ny];
int med=(ly+ry)>>1;
return gcd2(query_y2(ny*2,ly,med,nx,y1,y2),query_y2(ny*2+1,med+1,ry,nx,y1,y2));
}
int query_x2(int nx,int lx,int rx,int x1,int y1,int x2,int y2){
if(lx>x2||rx<x1)
return 0;
if(lx>=x1&&rx<=x2)
return query_y2(1,0,m-1,nx,y1,y2);
int med=(lx+rx)>>1;
return gcd2(query_x2(nx*2,lx,med,x1,y1,x2,y2),query_x2(nx*2+1,med+1,rx,x1,y1,x2,y2));
}
int query_y(int ny,int ly,int ry,int nx,int y1,int y2){
if(ly>y2||ry<y1)
return 0;
if(ly>=y1&&ry<=y2)
return st[nx][ny];
int med=(ly+ry)>>1;
return gcd2(query_y(ny*2,ly,med,nx,y1,y2),query_y(ny*2+1,med+1,ry,nx,y1,y2));
}
int query_x(int nx,int lx,int rx,int x1,int y1,int x2,int y2){
if(lx>x2||rx<x1)
return 0;
if(lx>=x1&&rx<=x2)
return query_y(1,0,m-1,nx,y1,y2);
int med=(lx+rx)>>1;
return gcd2(query_x(nx*2,lx,med,x1,y1,x2,y2),query_x(nx*2+1,med+1,rx,x1,y1,x2,y2));
}
void init(int R, int C) {
n=R,m=C;
}
void update(int P, int Q, long long K) {
if(n<=10&&m<=100000)
update_x2(1,0,n-1,P,Q,K);
else
update_x(1,0,n-1,P,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
if(n<=10&&m<=100000) return query_x2(1,0,n-1,P,Q,U,V);
return query_x(1,0,n-1,P,Q,U,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;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |