답안 #96815

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

#ifdef __cplusplus
extern "C" {
#endif

#include <math.h>

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;

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;
	int h = (int)ceil(log2(n+1))+1;
    tree = new T*[1 << h];
    for(int i=0; i<(1<<h); i++){
    	h = (int)ceil(log2(m+1))+1;
    	tree[i] = new T[1 << h];
    	for(int j=0; j<(1<<h); 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 Correct 2 ms 256 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 3 ms 868 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 896 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Runtime error 4 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Runtime error 126 ms 140152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 896 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 896 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Runtime error 3 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Runtime error 3 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -