记录编号 |
587635 |
评测结果 |
AAAAAAAAAA |
题目名称 |
磁力块 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
1.451 s |
提交时间 |
2024-04-10 22:15:37 |
内存使用 |
13.83 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 3e5+10;
const ll inf = 1e17;
int p,r,n;
ll x,y;
struct made{
ll m,p,r,le;
}a[N];
bool cmp1(made x,made y){return x.m < y.m;}
bool cmp2(made x,made y){return x.le < y.le;}
int L[N],R[N],B,t,bl[N];
int mx[N];
void prework(){
B = sqrt(n),t = (n-1)/B+1;
for(int i = 1;i <= t;i++)L[i] = (i-1)*B+1,R[i] = min(i*B,n);
for(int i = 1;i <= n;i++)bl[i] = (i-1)/B+1;
sort(a+1,a+1+n,cmp1);
for(int i = 1;i <= t;i++)mx[i] = a[R[i]].m,sort(a+L[i],a+R[i]+1,cmp2);
}
queue<made>q;
int ans = 0;
bool v[N];
int main(){
freopen("magnet.in","r",stdin);
freopen("magnet.out","w",stdout);
scanf("%lld%lld%d%d%d",&x,&y,&p,&r,&n);
for(int i = 1;i <= n;i++){
ll xx,yy;
scanf("%lld%lld%lld%lld%lld",&xx,&yy,&a[i].m,&a[i].p,&a[i].r);
a[i].le = (xx-x)*(xx-x) + (yy-y)*(yy-y);
}
prework();
q.push((made){0,p,r,0});
while(!q.empty()){
made x = q.front();q.pop();
for(int i = 1;i <= t;i++){
if(mx[i] <= x.p){
for(int j = L[i];j <= R[i];j++){
if(v[j]){L[i] = j+1;continue;}
if(a[j].le <= x.r*x.r)q.push(a[j]),ans++,v[j] = 1,L[i] = j+1;
else break;
}
}
else{
for(int j = L[i];j <= R[i];j++)
if(!v[j] && a[j].m <= x.p && a[j].le <= x.r*x.r)q.push(a[j]),ans++,v[j] = 1;
break;
}
}
}
printf("%d\n",ans);
return 0;
}