Codeforces 198E

来源:互联网 发布:手机淘宝社区在哪 编辑:程序博客网 时间:2024/05/29 03:59

线段树+set
这样就可以保证,每个爪子只被拿走一次,并且只更新一次,
并且更新的复杂度总的来说为n(logn)2

#include <cstdio>#include <iostream>#include <algorithm>#include <set>using namespace std;int i,j,k,X,Y,all,tot,n,M[250011],P[250011],R[250011],Left[500011],Right[500011],PP[250011],dl[250011],sum[500011];long long x,y,p,r,D[250011],RR[250011];bool used[250011];set<pair<int,int> > ent[500011];bool cmp(int a,int b){    return D[a]<D[b];}void build(int s,int e,int now){    sum[now]=e-s+1;    for (int i=s; i<=e; i++)        ent[now].insert(pair<int,int>(M[dl[i]],dl[i]));    if (s==e) return ;    int mid=(s+e)/2;    Left[now]=++tot;    build(s,mid,tot);    Right[now]=++tot;    build(mid+1,e,tot);}void quick(long long A,int b,int l,int r,int now){    if (sum[now]==0 || D[dl[l]]>A) return ;    if (D[dl[r]]<=A){        set<pair<int,int> >::iterator cp;        while (sum[now] && ent[now].begin()->first<=b){            cp=ent[now].begin();            int o=cp->second;            if (!used[o])            {                used[o]=true;                PP[++all]=P[o];                RR[all]=(long long)R[o]*R[o];            }            ent[now].erase(cp);            sum[now]--;        }        return ;    }    int mid=(l+r)/2;    quick(A,b,l,mid,Left[now]);    if (D[dl[mid+1]]<=A) quick(A,b,mid+1,r,Right[now]);}int main(){    cin >> x >> y >> p >> r >> n;    for (i=1; i<=n; i++)        scanf("%d%d%d%d%d",&X,&Y,&M[i],&P[i],&R[i]),D[i]=(X-x)*(X-x)+(Y-y)*(Y-y),dl[i]=i;    sort(dl+1,dl+n+1,cmp);    build(1,n,0);    PP[0]=p;    RR[0]=r*r;    for (i=0; all<=n && i<=all; i++)        quick(RR[i],PP[i],1,n,0);    cout << all;    return 0;}
0 0