#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <set>
#include <utility>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
#define x first
#define y second
#define mp make_pair
struct query{
ll x, y, r;
};
ll n, m, k;
query a[105];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
cin >> k;
for(int i = 0 ; i < k ; ++i){
cin >> a[i].x >> a[i].y >> a[i].r;
}
ll sol = 0;
for(int i = 1 ; i <= m ; ++i){
ll last = 1;
vector <pll> v;
for(int j = 0 ; j < k ; ++j){
ll x = a[j].x, y = a[j].y, r = a[j].r, val = j + 1;
if(i >= max(1LL, y - r) && i <= min(m, y + r)){
ll koef = (r - i + y) * (r + i - y);
ld t = sqrt(koef);
koef = (ll)t;
v.push_back(mp(max(1LL, x - koef), val));
v.push_back(mp(min(n + 1, x + koef + 1), -val));
}
}
set <ll, greater <ll> > s;
sort(v.begin(), v.end());
for(int j = 0 ; j < v.size() ; ){
ll t = v[j].x;
sol += (t - last) * (k - (!s.empty() ? *s.begin() : 0LL));
while(j < v.size() && v[j].x == t){
ll o = v[j].y;
if(o < 0){
s.erase(s.find(-o));
}
else{
s.insert(o);
}
j++;
}
last = t;
}
sol += (n + 1 - last) * k;
}
cout << sol << endl;
return 0;
}
Compilation message
nlo.cpp: In function 'int main()':
nlo.cpp:51:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0 ; j < v.size() ; ){
~~^~~~~~~~~~
nlo.cpp:54:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j < v.size() && v[j].x == t){
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
12 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
376 KB |
Output is correct |
4 |
Correct |
41 ms |
380 KB |
Output is correct |
5 |
Correct |
42 ms |
256 KB |
Output is correct |
6 |
Correct |
237 ms |
376 KB |
Output is correct |
7 |
Correct |
108 ms |
376 KB |
Output is correct |
8 |
Correct |
452 ms |
504 KB |
Output is correct |
9 |
Correct |
190 ms |
380 KB |
Output is correct |
10 |
Correct |
616 ms |
476 KB |
Output is correct |