#include "game.h"
#include <bits/stdc++.h>
using namespace std;
vector< vector<long long> > seg;
int _R, _C;
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_coluna (int l, int r, int node, long long delta, int coluna, int node_linha, bool is_merge) {
if (l > coluna || r < coluna) return;
if (l == coluna && r == coluna) {
if (is_merge) seg[node_linha][node] = delta;
else seg[node_linha][node] = gcd2 (seg[2 * node_linha + 1][node], seg[2 * node_linha + 2][node]);
return;
}
int mid = l + (r - l) / 2;
update_coluna (l, mid, 2 * node + 1, delta, coluna, node_linha, is_merge);
update_coluna (mid + 1, r, 2 * node + 2, delta, coluna, node_linha, is_merge);
if (is_merge) {
seg[node_linha][node] = gcd2 (seg[node_linha][2 * node + 1], seg[node_linha][2 * node + 2]);
} else {
seg[node_linha][node] = gcd2 (seg[2 * node_linha + 1][node], seg[2 * node_linha + 2][node]);
}
}
void update_linha (int l, int r, int node, int linha, long long delta, int coluna) {
if (l > linha || r < linha) return;
if (l == linha && r == linha) {
update_coluna (0, _C - 1, 0, delta, coluna, node, true);
return;
}
int mid = l + (r - l) / 2;
update_linha (l, mid, 2 * node + 1, linha, delta, coluna);
update_linha (mid + 1, r, 2 * node + 2, linha, delta, coluna);
update_coluna (0, _C - 1, 0, delta, coluna, node, false);
}
long long query_coluna (int l, int r, int node, int coluna_inicio, int coluna_fim, int node_linha) {
if (l > coluna_fim || r < coluna_inicio) return 0;
if (l >= coluna_inicio && r <= coluna_fim) return seg[node_linha][node];
int mid = l + (r - l) / 2;
return gcd2 ( query_coluna (l, mid, 2 * node + 1, coluna_inicio, coluna_fim, node_linha),
query_coluna (mid + 1, r, 2 * node + 2, coluna_inicio, coluna_fim, node_linha) );
}
long long query_linha (int l, int r, int node, int linha_inicio, int linha_fim, int coluna_inicio, int coluna_fim) {
if (l > linha_fim || r < linha_fim) return 0;
if (l >= linha_inicio && r <= linha_fim) {
return query_coluna (0, _C - 1, 0, coluna_inicio, coluna_fim, node);
}
int mid = l + (r - l) / 2;
return gcd2 ( query_linha (l, mid, 2 * node + 1, linha_inicio, linha_fim, coluna_inicio, coluna_fim),
query_linha (mid + 1, r, 2 * node + 2, linha_inicio, linha_fim, coluna_inicio, coluna_fim) );
}
void init(int R, int C) {
_R = R;
_C = C;
seg = vector< vector<long long> > (4 * R, vector<long long> (4 * C, 0LL));
}
void update(int P, int Q, long long K) {
update_linha (0, _R - 1, 0, P, K, Q);
}
long long calculate(int P, int Q, int U, int V) {
return query_linha (0, _R - 1, 0, P, U, Q, 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;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1536 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
128 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1536 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Incorrect |
6 ms |
1664 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Incorrect |
6 ms |
1536 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |