#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define N 100500
#define oo ll(1e16)
#define ft first
#define sd second
#define pb push_back
#define ppb pop_back
#define el '\n'
#define elf endl
#define base ll(1e9 + 7)
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m, k, a[N], b[N], r[N], res;
ll sqr(ll x) { return x * x; }
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= k; i++)
cin >> a[i] >> b[i] >> r[i], a[i]--, b[i]--;
for (int i = 0; i < n; i++) {
vector <pair <ll, ll> > v;
v.clear();
for (int j = 1; j <= k; j++) {
if (i < a[j] - r[j] || i > a[j] + r[j])
continue;
ll dist = sqrt(sqr(r[j]) - sqr(a[j] - i));
v.pb({b[j] - dist, j});
v.pb({b[j] + dist + 1, -j});
}
sort(v.begin(), v.end());
set <ll> s;
for (int j = 0; j < sz(v); j++) {
if (!s.empty())
res += (*s.rbegin()) * (v[j].ft - v[j - 1].ft);
if (v[j].sd < 0) s.erase(-v[j].sd);
else s.insert(v[j].sd);
}
}
cout << (n * m * k) - res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
256 KB |
Output is correct |
2 |
Correct |
17 ms |
384 KB |
Output is correct |
3 |
Correct |
14 ms |
384 KB |
Output is correct |
4 |
Correct |
70 ms |
384 KB |
Output is correct |
5 |
Correct |
49 ms |
384 KB |
Output is correct |
6 |
Correct |
395 ms |
416 KB |
Output is correct |
7 |
Correct |
138 ms |
384 KB |
Output is correct |
8 |
Correct |
731 ms |
384 KB |
Output is correct |
9 |
Correct |
262 ms |
504 KB |
Output is correct |
10 |
Correct |
974 ms |
504 KB |
Output is correct |