#include "game.h"
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
long long gcd(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;
void update_1d(int i, ll k, vector<ll>& v){
for (i += c; i > 0; i >>= 1) v[i] = gcd(v[i], k);
}
ll query_1d(int li, int ri, vector<ll>& v) {
ll g = 0;
for (li += c, ri += c + 1; li < ri; li >>= 1, ri >>= 1) {
if (li & 1) g = gcd(g, v[li++]);
if (ri & 1) g = gcd(g, v[--ri]);
} return g;
}
vector<vector<ll> > st;
void init(int R, int C) {
r = R, c = C;
st.assign(r * 2, vector<ll>(c * 2, 0));
}
void update(int x, int y, long long k) {
for (x += r; x > 0; x >>= 1) update_1d(y, k, st[x]);
}
long long calculate(int lx, int ly, int rx, int ry) {
ll g = 0;
for (lx += r, rx += r + 1; lx < rx; lx >>= 1, rx >>= 1) {
if (lx & 1) g = gcd(g, query_1d(ly, ry, st[lx++]));
if (rx & 1) g = gcd(g, query_1d(ly, ry, st[--rx]));
}
return g;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |