#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e5 + 10;
const ll mod = 1e9 + 7;
ll um(ll a, ll b){
return ((1LL * a * b) % mod + mod) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
ll add(ll a, ll b){
return ((1LL * a + b) % mod + mod) % mod;
}
ll binpow(ll x, ll step){
ll res = 1LL;
while(step){
if(step & 1) res = um(res, x);
x = um(x, x);
step /= 2;
}
return res;
}
/*
Восемь восемьсот пять пять пять
три пять три пять
Проще кому то позвонить
чем у кого-то деньги занимать
*/
ll x[N], y[N], rd[N];
vector <pll> vec[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n, m, q, ans = 0;
cin >> n >> m >> q;
for(ll i = 0; i < q; i++){
cin >> x[i] >> y[i] >> rd[i];
rd[i] *= rd[i];
}
for(ll i = 1; i <= n; i++){
vec[i].pb({1, m});
}
for(ll i = q - 1; i >= 0; i--){
for(ll j = 1; j <= n; j++){
if((j - x[i]) * (j - x[i]) > rd[i]) continue;
ll l = y[i], r = m + 1, ansl, ansr;
while(r - l > 1){
ll mid = (r + l) / 2;
ll s1 = (mid - y[i]) * (mid - y[i]);
ll s2 = (j - x[i]) * (j - x[i]);
if(s1 + s2 <= rd[i]) l = mid;
else r = mid;
}
ansr = l;
l = 0;
r = y[i];
while(r - l > 1){
ll mid = (r + l) / 2;
ll s1 = (mid - y[i]) * (mid - y[i]);
ll s2 = (j - x[i]) * (j - x[i]);
if(s1 + s2 <= rd[i]) r = mid;
else l = mid;
}
ansl = r;
vector <pll> nw;
for(auto u : vec[j]){
if(ansl <= u.F && u.S <= ansr){
ans += (q - i - 1) * (u.S - u.F + 1);
continue;
}
if(u.F <= ansl && ansr <= u.S){
ans += (q - i - 1) * (ansr - ansl + 1);
if(u.F < ansl) nw.pb({u.F, ansl - 1});
if(ansr < u.S) nw.pb({ansr + 1, u.S});
continue;
}
if(u.F <= ansl && ansl <= u.S){
ans += (q - i - 1) * (u.S - ansl + 1);
if(u.F < ansl) nw.pb({u.F, ansl - 1});
continue;
}
if(u.F <= ansr && ansr <= u.S){
ans += (q - i - 1) * (ansr - u.F + 1);
if(ansr < u.S) nw.pb({ansr + 1, u.S});
continue;
}
nw.pb(u);
}
swap(nw, vec[j]);
}
}
for(ll i = 1; i <= n; i++){
for(auto u : vec[i]){
ans += q * (u.S - u.F + 1);
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Correct |
6 ms |
4700 KB |
Output is correct |
3 |
Correct |
8 ms |
5164 KB |
Output is correct |
4 |
Correct |
41 ms |
4952 KB |
Output is correct |
5 |
Correct |
52 ms |
5976 KB |
Output is correct |
6 |
Correct |
292 ms |
7304 KB |
Output is correct |
7 |
Correct |
144 ms |
8024 KB |
Output is correct |
8 |
Correct |
592 ms |
9368 KB |
Output is correct |
9 |
Correct |
257 ms |
10576 KB |
Output is correct |
10 |
Correct |
812 ms |
10220 KB |
Output is correct |