I don‘t know
2074D - Counting Points
For some value of xx and a circle centered on (xi,0)(xi,0) with radius riri, we can find the range of yy where the points lie on using simple algebra.
y2≤r2i−(x−xi)2⟹−r2i−(x−xi)2−−−−−−−−−−−√≤y≤r2i−(x−xi)2−−−−−−−−−−−√y2≤ri2−(x−xi)2⟹−ri2−(x−xi)2≤y≤ri2−(x−xi)2
Here, we can see that when a=⌊r2i−(x−xi)2−−−−−−−−−−−√⌋a=⌊ri2−(x−xi)2⌋, there are 2a+12a+1 different integer values of yy in this range.
Now, think of how to deal with when multiple circles cover the same value of xx. This is not too hard; you can compute the value of aa for all of them and take the largest one. The rest can be ignored as the largest value of aa covers all of them.
The implementation is not hard; it simply boils down to using a std::map or some data structure to record the maximum value of aa for each value of xx that holds at least one point. The problem is solved in time complexity O(mlogm)O(mlogm).
It is technically possible to solve the problem by fixing the value of yy instead of the value of xx, but it is significantly more tedious to implement.
Code
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
int t;cin>>t;
for(int i=0;i<t;i++)
{
int n,m;cin>>n>>m;
map<ll,ll>cnt;
auto isqrt=[&](ll x)
{
ll val=sqrtl(x)+5;
while(val*val>x)val--;
return val;
};
vector<ll>a(n),r(n);
for(ll&i:a)cin>>i;
for(ll&i:r)cin>>i;
for(int i=0;i<n;i++)
{
ll aa=a[i],rr=r[i];
for(ll x=aa-rr;x<=aa+rr;x++)
{
cnt[x]=max(cnt[x],2*isqrt(rr*rr-(x-aa)*(x-aa))+1);
}
}
ll ans=0;
for(auto[x,c]:cnt)ans+=c;
cout<<ans<<"\n";
}
}