#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 22;
const ll MAXN = 1e5 + 5;
#define int long long
int x[105], y[105], r[105];
int sg[4*MAXN], lazy[4*MAXN];
void push(int k, int a, int b) {
if (lazy[k] != -1) {
sg[k] = (b - a + 1) * lazy[k];
if (a != b) {
lazy[2*k] = lazy[k];
lazy[2*k+1] = lazy[k];
}
lazy[k] = -1;
}
}
void update(int k, int a, int b, int q_l, int q_r, int v) {
push(k, a, b);
if (q_r < a || q_l > b)
return ;
if (q_l <= a && b <= q_r) {
lazy[k] = v;
push(k, a, b);
return ;
}
update(2*k, a, (a+b)/2, q_l, q_r, v);
update(2*k+1, (a+b)/2+1, b, q_l, q_r, v);
sg[k] = sg[2*k] + sg[2*k+1];
}
int query(int k, int a, int b, int q_l, int q_r) {
if (b < q_l || a > q_r)
return 0;
push(k, a, b);
if (q_l <= a && b <= q_r)
return sg[k];
return query(2*k, a, (a+b)/2, q_l, q_r) + query(2*k+1, (a+b)/2 + 1, b, q_l, q_r);
}
signed main() {
fast
memset(lazy, -1, sizeof(lazy));
int N, M, K;
cin >> N >> M >> K;
for (int i = 0; i < K; i++)
cin >> y[i] >> x[i] >> r[i];
ll ans = 0;
for (int i = 1; i <= N; i++) {
update(1, 1, M, 1, M, 1);
for (int circ = K-1; circ >= 0; circ--) {
int hei = abs(y[circ] - i);
if (hei > r[circ])
continue;
hei *= hei;
int sqr = sqrt(r[circ] * r[circ] - hei);
ans += (K-1-circ) * query(1, 1, M, x[circ] - sqr, x[circ] + sqr);
update(1, 1, M, x[circ] - sqr, x[circ] + sqr, 0);
}
ans += K * query(1, 1, M, 1, M);
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4700 KB |
Output is correct |
2 |
Correct |
17 ms |
4752 KB |
Output is correct |
3 |
Correct |
15 ms |
4700 KB |
Output is correct |
4 |
Correct |
130 ms |
4696 KB |
Output is correct |
5 |
Correct |
127 ms |
4700 KB |
Output is correct |
6 |
Correct |
965 ms |
4720 KB |
Output is correct |
7 |
Correct |
438 ms |
5616 KB |
Output is correct |
8 |
Correct |
2040 ms |
5760 KB |
Output is correct |
9 |
Correct |
723 ms |
5724 KB |
Output is correct |
10 |
Correct |
2767 ms |
5804 KB |
Output is correct |