답안 #96808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96808 2019-02-12T08:30:03 Z jhnah917 게임 (IOI13_game) C++14
0 / 100
519 ms 257024 KB
#ifndef __GAME_H__
#define __GAME_H__

#ifdef __cplusplus
extern "C" {
#endif


void init(int R, int C);
void update(int P, int Q, long long K);
long long calculate(int P, int Q, int U, int V);
int n, m;

long long f(long long X, long long Y) {
    long long tmp;
    while (X != Y && Y != 0) {
        tmp = X;
        X = Y;
        Y = tmp % Y;
    }
    return X;
}

typedef long long T;

T tree[8080][8080];

T ysum(int xnode, int ynode, int ys, int ye, int yl, int yr){
	if(yr < ys || ye < yl) return 0;
	if(yl <= ys && ye <= yr) return tree[xnode][ynode];
	int ym = (ys + ye) >> 1;
	return f(ysum(xnode, ynode*2, ys, ym, yl, yr), ysum(xnode, ynode*2+1, ym+1, ye, yl, yr));
}

T xsum(int xnode, int xs, int xe, int xl, int xr, int yl, int yr){
	if(xr < xs || xe < xl) return 0;
	if(xl <= xs && xe <= xr) return ysum(xnode, 1, 0, m-1, yl, yr);
	int xm = (xs + xe) >> 1;
	return f(xsum(xnode*2, xs, xm, xl, xr, yl, yr), xsum(xnode*2+1, xm+1, xe, xl, xr, yl, yr));
}

void yupdate(int xnode, int xs, int xe, int ynode, int ys, int ye, int x, int y, T val){
	if(ye < y || y < ys) return;
	if(ys^ye){
		int ym = (ys + ye) >> 1;
		yupdate(xnode, xs, xe, ynode*2, ys, ym, x, y, val), yupdate(xnode, xs, xe, ynode*2+1, ym+1, ye, x, y, val);
		tree[xnode][ynode] = f(tree[xnode][ynode*2], tree[xnode][ynode*2+1]);
	}else{
		if(xs^xe) tree[xnode][ynode] = f(tree[xnode*2][ynode], tree[xnode*2+1][ynode]);
		else tree[xnode][ynode] = val;
	}
}

void xupdate(int xnode, int xs, int xe, int x, int y, T val){
	if(xe < x || x < xs) return;
	if(xs^xe){
		int xm = (xs + xe) >> 1;
		xupdate(xnode*2, xs, xm, x, y, val), xupdate(xnode*2+1, xm+1, xe, x, y, val);
	}
	yupdate(xnode, xs, xe, 1, 0, m-1, x, y, val);
}

void init(int R, int C) {
	n = R, m = C;
    for(int i=0; i<8080; i++) for(int j=0; j<8080; j++) tree[i][j] = 0LL;
}

void update(int x, int y, long long val) {
    xupdate(1, 0, n-1, x, y, val);
}

long long calculate(int x1, int y1, int x2, int y2) {
    return xsum(1, 0, n-1, x1, x2, y1, y2);
}

#ifdef __cplusplus
}
#endif

#endif /* __GAME_H__ */

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;
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 418 ms 257024 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 452 ms 257024 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 519 ms 257024 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 203 ms 257024 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 210 ms 257024 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -