#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define N 200010
int ans,x[N],y[N],r[N],sq[N];
struct A{
int l,r,w;
};
vector<A>v;
vector<int>u;
int a[1010];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,i,j,k;
cin>>n>>m>>k;
for(i=0;i<N;i++)sq[i]=i*i;
for(i=1;i<=k;i++) cin>>x[i]>>y[i]>>r[i];
for(j=1;j<=n;j++){
vector<int>().swap(u);
vector<A>().swap(v);
for(i=1;i<=k;i++){
int xx=r[i]*r[i]-(j-x[i])*(j-x[i]);
if(xx<0)continue;
int p=upper_bound(sq,sq+N,xx)-sq-1;
v.pb({y[i]-p,y[i]+p+1,i});
u.pb(v.back().l);
u.pb(v.back().r);
}
if(n<=1000){
memset(a,0,sizeof(a));
for(auto[l,r,w]:v){
for(i=l;i<r;i++)a[i]=max(w,a[i]);
}
for(i=1;i<=m;i++)ans+=a[i];
continue;
}
sort(all(u)),u.resize(unique(all(u))-u.begin());
for(auto&[l,r,w]:v){
l=lower_bound(all(u),l)-u.begin();
r=lower_bound(all(u),r)-u.begin();
}
sort(all(v),[](A u,A v){return u.l<v.l;});
priority_queue<pii>pq;
pq.push({0,1e9});
int l=1,x;
for(i=0,x=0;i<u.size();i++){
ans+=(u[i]-l)*pq.top().ff;
l=u[i];
while(x<k&&v[x].l==i)pq.push({v[x].w,v[x].r}),x++;
while(pq.top().ss<=i)pq.pop();
}
}
cout<<n*m*k-ans<<'\n';
}
Compilation message
nlo.cpp: In function 'int main()':
nlo.cpp:52:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(i=0,x=0;i<u.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1876 KB |
Output is correct |
2 |
Correct |
19 ms |
1928 KB |
Output is correct |
3 |
Incorrect |
9 ms |
1876 KB |
Output isn't correct |
4 |
Incorrect |
68 ms |
1876 KB |
Output isn't correct |
5 |
Incorrect |
45 ms |
1896 KB |
Output isn't correct |
6 |
Incorrect |
370 ms |
1912 KB |
Output isn't correct |
7 |
Incorrect |
129 ms |
1876 KB |
Output isn't correct |
8 |
Incorrect |
720 ms |
1908 KB |
Output isn't correct |
9 |
Incorrect |
232 ms |
1876 KB |
Output isn't correct |
10 |
Incorrect |
952 ms |
1912 KB |
Output isn't correct |