contesthunter#46-A(分块)
http://begin.lydsy.com/JudgeOnline/upload/4840.pdf
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; const double eps=1e-6; struct my{ ll m,p,x,y; double dis,r; }; const int maxn=250000+10; my a[maxn]; bool vis[maxn]; ll maxx[maxn]; ll L[maxn],R[maxn],que[maxn],to[maxn]; bool cmp1(const my &x,const my &y){ return x.m<y.m; } bool cmp2(const my &x,const my &y){ return x.dis<y.dis; } int main(){ ll x0,y0,p,n; double r; double x,y; scanf("%lld%lld%lld%lf%lld",&x0,&y0,&p,&r,&n); for (int i=1;i<=n;i++){ scanf("%lf%lf%lld%lld%lf",&x,&y,&a[i].m,&a[i].p,&a[i].r); a[i].dis=sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0)); } a[0].x=x0,a[0].y=y0,a[0].p=p,a[0].r=r; int tot=sqrt(1.0*n+0.1); sort(a+1,a+1+n,cmp1); for (int i=1;i<=tot;i++){ L[i]=R[i-1]+1; to[i]=L[i]; R[i]= i==tot?n:L[i]+tot; maxx[i]=a[R[i]].m; } for (int i=1;i<=tot;i++) sort(a+L[i],a+R[i]+1,cmp2); que[0]=0; int ll=0; int rr=0; int i=0; int pp=0; int ans=0; while(ll<=rr){ pp=que[ll++]; for (i=1;i<=tot&&a[pp].p>=maxx[i];i++){ for (int j=to[i];j<=R[i]&&a[pp].r+eps>=a[j].dis;j++){ if(!vis[j]){ to[i]++; que[++rr]=j; ans++; vis[j]=true; } } } if(i<=tot){//记得写i<=tot。。。。。 for (int k=L[i];k<=R[i];k++){ if(a[pp].p>=a[k].m&&a[pp].r+eps>=a[k].dis) { if(!vis[k]){ que[++rr]=k;ans++; vis[k]=true; } } } } } printf("%d",ans); return 0; }