Link
题意:
思路:
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5;
int n,t;
ll x_0,y_0;
int cnt;
int L[500],R[500],M[500];
bool st[N];
int ans;
struct node {
int m,p;
ll d,r;
}s[N];
bool cmp1(node a,node b) {
return a.m<b.m;
}
bool cmp2(node a,node b) {
return a.d<b.d;
}
void pre() {
cin>>x_0>>y_0>>s[0].p>>s[0].r>>n;
s[0].r*=s[0].r;
for(int i=1;i<=n;i++) {
ll x,y,r;
int m,p;
cin>>x>>y>>m>>p>>r;
s[++cnt]={m,p,(x-x_0)*(x-x_0)+(y-y_0)*(y-y_0),r*r};
}
sort(s+1,s+1+n,cmp1);
t=sqrt(n);
for(int i=1;i<=t;i++) {
L[i]=R[i-1]+1;
R[i]=i*t;
}
if(R[t]<n) t++,L[t]=R[t-1]+1,R[t]=n;
for(int i=1;i<=t;i++) {
M[i]=s[R[i]].m;
sort(s+L[i],s+1+R[i],cmp2);
}
}
void bfs() {
queue<int>q;
q.push(0);
while(!q.empty()) {
int now=q.front();
q.pop();
for(int i=1;i<=t;i++) {
if(M[i]>s[now].p) {
for(int j=L[i];j<=R[i];j++) {
if(!st[j]&&s[j].m<=s[now].p&&s[j].d<=s[now].r) {
st[j]=true;
ans++;
q.push(j);
}
else if(s[j].d>s[now].r) break;
}
break;
}
while(L[i]<=R[i]&&s[L[i]].d<=s[now].r) {
if(!st[L[i]]) {
st[L[i]]=true;
ans++;
q.push(L[i]);
}
L[i]++;
}
}
}
}
int main() {
//freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0);
pre();
bfs();
cout<<ans<<endl;
return 0;
}