답안 #97668

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97668 2019-02-17T17:21:13 Z tincamatei 게임 (IOI13_game) C++14
0 / 100
4 ms 896 KB
#include "game.h"
#include <bits/stdc++.h>

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;
}

int R, C;
long long aint[401][401];

void updateSmall(int anod, int poz, long long val, int l, int r, int nod = 1) {
	if(poz < l || r < poz) return;
	if(l == r)
		aint[anod][nod] = val;
	else {
		int mid = (l + r) / 2;
		updateSmall(anod, poz, val, l, mid, 2 * nod);
		updateSmall(anod, poz, val, mid + 1, r, 2 * nod + 1);
		aint[anod][nod] = gcd2(aint[anod][2 * nod], aint[anod][2 * nod + 1]);
	}
}

void updateBig(int i, int j, long long val, int l, int r, int nod = 1) {
	if(i < l || r < i) return;
	updateSmall(nod, j, val, 0, C - 1);
	if(l < r) {
		int mid = (l + r) / 2;
		updateBig(i, j, val, l, mid, 2 * nod);
		updateBig(i, j, val, mid + 1, r, 2 * nod + 1);
	}
}

long long querySmall(int anod, int i, int j, int l, int r, int nod = 1) {
	if(r < i || j < l) return 0;
	if(i <= l && r <= j)
		return aint[anod][nod];
	else {
		int mid = (l + r) / 2;
		return gcd2(querySmall(anod, i, j, l, mid, 2 * nod),
		            querySmall(anod, i, j, mid + 1, r, 2 * nod + 1));
	}
}

long long queryBig(int p, int q, int u, int v, int l, int r, int nod = 1) {
	if(r < p || u < l) return 0;
	if(p <= l && r <= u)
		return querySmall(nod, q, v, 0, C - 1);
	else {
		int mid = (l + r) / 2;
		return gcd2(queryBig(p, q, u, v, l, mid, 2 * nod),
		            queryBig(p, q, u, v, mid + 1, r, 2 * nod + 1));
	}
}

void init(int _R, int _C) {
	R = _R;
	C = _C;
	//aint = new long long*[1+4*_R];
	//for(int i = 0; i < 1 + 4 * _R; ++i) {
	//	aint[i] = new long long[1+4*_C];
	//	for(int j = 0; j < 1 + 4 * _C; ++j)
	//		aint[i][j] = 0;
	//}
}

void update(int P, int Q, long long K) {
	updateBig(P, Q, K, 0, R - 1);
}

long long calculate(int P, int Q, int U, int V) {
	return queryBig(P, Q, U, V, 0, R - 1);
}

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 Incorrect 4 ms 896 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 3 ms 896 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 3 ms 896 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 3 ms 896 KB Output isn't correct
3 Halted 0 ms 0 KB -