Submission #750945

#TimeUsernameProblemLanguageResultExecution timeMemory
750945alex_2008Game (IOI13_game)C++14
0 / 100
0 ms212 KiB
#include "game.h"
#include <vector>
typedef long long ll;
using namespace std;
const int N = 110, M = 100100;
ll tree[N][4 * M];
int H, W;
ll __gcd(ll a, ll b) {
	while (a && b) {
		(a > b) ? a %= b : b %= a;
	}
	return a + b;
}
void update1(int R, int C, int value, int v, int tl, int tr) {
	if (tl > C || tr < C) {
		return;
	}
	if (tl == tr) {
		tree[R][v] = value;
		return;
	}
	int tm = (tl + tr) / 2;
	update1(R, C, value, 2 * v, tl, tm);
	update1(R, C, value, 2 * v + 1, tm + 1, tr);
	tree[R][v] = __gcd(tree[R][2 * v], tree[R][2 * v + 1]);
}
ll GCD(int R, int v, int tl, int tr, int l, int r) {
	if (tl >= l && tr <= r) return tree[R][v];
	if (tl > r || tr < l) return 0;
	int tm = (tl + tr) / 2;
	return __gcd(GCD(R, 2 * v, tl, tm, l, r),
		GCD(R, 2 * v + 1, tm + 1, tr, l, r));
}
void init(int R, int C) {
	H = R;
	W = C;
}
void update(int R, int Q, long long K) {
	update1(R, Q, K, 1, 0, W - 1);
}
long long calculate(int P, int Q, int U, int V) {
	ll u = 0;
	for (int i = P; i <= U; i++) {
		u = __gcd(u, GCD(i, 1, 0, W - 1, Q, V));
	}
	return u;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...