Submission #318522

# Submission time Handle Problem Language Result Execution time Memory
318522 2020-11-02T08:53:31 Z IloveN Circle selection (APIO18_circle_selection) C++14
49 / 100
3000 ms 397784 KB
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(vr) vr.begin(),vr.end()
#define vi vector<int>
#define vll vector<ll>
const int N=3e5+10;
const ll inf=1e9;
struct circle{int x,y,r,id;};

circle a[N];
int n;

struct segment_tree_2d
{
    vi pre[N*4],nex[N*4],pos_in[N],bit[N*4];
    vector<pii> val[N*4];
    pii arr[N];
    int len,lg[N*4];

    void add(int id,int pos,int x)
    {
        for (int i=pos;i<(int)bit[id].size();i+=(i&-i)) bit[id][i]+=x;
    }

    int get(int id,int pos)
    {
        int res=0;
        for (int i=pos;i;i-=(i&-i)) res+=bit[id][i];
        return res;
    }

    int lw(int id,int x)
    {
        int sum=0,res=0,len=val[id].size();
        for (int i=lg[id];i>=0;i--)
            if (res+(1<<i)<=len && sum+bit[id][res+(1<<i)]<=x) res+=(1<<i),sum+=bit[id][res];
        return res+1;
    }

    void build(int id,int l,int r)
    {
        if (l==r)
        {
            val[id].eb(arr[l]);
            bit[id].resize(2,1);
            pre[id].eb(-1);
            nex[id].eb(2);
            pos_in[l].eb(0);
            return;
        }
        int mid=(l+r)/2;
        build(id*2,l,mid);
        build(id*2+1,mid+1,r);
        val[id].resize(val[id*2].size()+val[id*2+1].size());
        merge(all(val[id*2]),all(val[id*2+1]),val[id].begin());
        int len=val[id].size();
        pre[id].resize(len);
        nex[id].resize(len);
        for (int i=0;i<len;i++) pre[id][i]=i-1,nex[id][i]=i+1,pos_in[val[id][i].se].eb(i);
        bit[id].resize(val[id].size()+1,0);
        for (int i=1;i<=len;i++) bit[id][i]=(i&-i);
        while (len>1) len>>=1,lg[id]++;
    }

    void input(pii ar[],int siz)
    {
        len=siz;
        for (int i=1;i<=len;i++) arr[i]=ar[i];
        for (int i=1;i<=len*4;i++) pos_in[i].reserve(20);
        build(1,1,len);
    }

    void update(int id,int l,int r,int v,int layer)
    {
        int pos=pos_in[v][layer];
        add(id,pos+1,-1);
        if (pre[id][pos]>-1) nex[id][pre[id][pos]]=nex[id][pos];
        if (nex[id][pos]<(int)val[id].size()) pre[id][nex[id][pos]]=pre[id][pos];
        if (l==r) return;
        int mid=(l+r)/2;
        if (v<=mid) update(id*2,l,mid,v,layer-1);
        else update(id*2+1,mid+1,r,v,layer-1);
    }

    vi pot;

    void searc(int id,int l,int r,int u,int v,int y1,int y2)
    {
        if (l>v || r<u) return;
        if (u<=l && r<=v)
        {
            int pos=lower_bound(all(val[id]),mp(y1,0))-val[id].begin();
            if (pos>(int)val[id].size()) return;
            pos=lw(id,get(id,pos))-1;
            if (pos<0) return;
            while (pos<(int)val[id].size() && val[id][pos].fi<=y2)
            {
                pot.eb(val[id][pos].se);
                pos=nex[id][pos];
            }
            return;
        }
        int mid=(l+r)/2;
        searc(id*2,l,mid,u,v,y1,y2);
        searc(id*2+1,mid+1,r,u,v,y1,y2);
    }

    vi find_pot(int u,int v,int y1,int y2)
    {
        pot.clear();
        if (u<=v) searc(1,1,n,u,v,y1,y2);
        return pot;
    }

    void del(vi &vt)
    {
        for (int x : vt) update(1,1,n,x,pos_in[x].size()-1);
    }
} seg;

void read()
{
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i].x>>a[i].y>>a[i].r,a[i].id=i;
}

bool cmp(circle &obj1, circle &obj2) { return (obj1.r>obj2.r) || ((obj1.r==obj2.r) && (obj1.id<obj2.id));}
pii X[N],Y[N];
int ans[N];

ll sqr(ll x) { return x*x;}

bool intersect(int i,int j)
{
    return sqr(a[i].x-a[j].x)+sqr(a[i].y-a[j].y)<=sqr(a[i].r+a[j].r);
}

void process()
{
    sort(a+1,a+n+1,cmp);
    for (int i=1;i<=n;i++) X[i]=mp(a[i].x,i);
    sort(X+1,X+n+1);
    for (int i=1;i<=n;i++) Y[i]=mp(a[X[i].se].y,i);
    seg.input(Y,n);
    for (int i=1;i<=n;i++)
    if (ans[a[i].id]==0)
    {
        int x1=max(-inf,(ll)a[i].x-a[i].r*2),x2=min(inf,(ll)a[i].x+a[i].r*2);
        int y1=max(-inf,(ll)a[i].y-a[i].r*2),y2=min(inf,(ll)a[i].y+a[i].r*2);
        int u=lower_bound(X+1,X+n+1,mp(x1,0))-X;
        int v=upper_bound(X+1,X+n+1,mp(x2,n+2))-X-1;
        vi vt=seg.find_pot(u,v,y1,y2);
        vi vt2;
        for (int x : vt)
            if (intersect(i,X[x].se)) ans[a[X[x].se].id]=a[i].id,vt2.eb(x);
        seg.del(vt2);
    }
    for (int i=1;i<=n;i++) cout<<ans[i]<<" ";
}

int main()
{
    //freopen("ss.inp","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    read();
    process();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 83 ms 122468 KB Output is correct
2 Correct 81 ms 122468 KB Output is correct
3 Correct 82 ms 122468 KB Output is correct
4 Correct 82 ms 122596 KB Output is correct
5 Correct 82 ms 122540 KB Output is correct
6 Correct 82 ms 122596 KB Output is correct
7 Correct 82 ms 122596 KB Output is correct
8 Correct 83 ms 122596 KB Output is correct
9 Correct 82 ms 122596 KB Output is correct
10 Correct 82 ms 122724 KB Output is correct
11 Correct 84 ms 122596 KB Output is correct
12 Correct 82 ms 122596 KB Output is correct
13 Correct 83 ms 122624 KB Output is correct
14 Correct 83 ms 122596 KB Output is correct
15 Correct 82 ms 122596 KB Output is correct
16 Correct 87 ms 123364 KB Output is correct
17 Correct 87 ms 123364 KB Output is correct
18 Correct 88 ms 123364 KB Output is correct
19 Correct 99 ms 126948 KB Output is correct
20 Correct 102 ms 126948 KB Output is correct
21 Correct 100 ms 126948 KB Output is correct
22 Correct 104 ms 126864 KB Output is correct
23 Correct 104 ms 126820 KB Output is correct
24 Correct 101 ms 126824 KB Output is correct
25 Correct 104 ms 126876 KB Output is correct
26 Correct 105 ms 126820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1233 ms 397784 KB Output is correct
2 Correct 1227 ms 396236 KB Output is correct
3 Correct 1236 ms 396884 KB Output is correct
4 Correct 1219 ms 397780 KB Output is correct
5 Correct 1335 ms 394416 KB Output is correct
6 Correct 1773 ms 394468 KB Output is correct
7 Correct 1367 ms 394596 KB Output is correct
8 Correct 1458 ms 394340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 122596 KB Output is correct
2 Correct 977 ms 212836 KB Output is correct
3 Execution timed out 3062 ms 394436 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3114 ms 394364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 122468 KB Output is correct
2 Correct 81 ms 122468 KB Output is correct
3 Correct 82 ms 122468 KB Output is correct
4 Correct 82 ms 122596 KB Output is correct
5 Correct 82 ms 122540 KB Output is correct
6 Correct 82 ms 122596 KB Output is correct
7 Correct 82 ms 122596 KB Output is correct
8 Correct 83 ms 122596 KB Output is correct
9 Correct 82 ms 122596 KB Output is correct
10 Correct 82 ms 122724 KB Output is correct
11 Correct 84 ms 122596 KB Output is correct
12 Correct 82 ms 122596 KB Output is correct
13 Correct 83 ms 122624 KB Output is correct
14 Correct 83 ms 122596 KB Output is correct
15 Correct 82 ms 122596 KB Output is correct
16 Correct 87 ms 123364 KB Output is correct
17 Correct 87 ms 123364 KB Output is correct
18 Correct 88 ms 123364 KB Output is correct
19 Correct 99 ms 126948 KB Output is correct
20 Correct 102 ms 126948 KB Output is correct
21 Correct 100 ms 126948 KB Output is correct
22 Correct 104 ms 126864 KB Output is correct
23 Correct 104 ms 126820 KB Output is correct
24 Correct 101 ms 126824 KB Output is correct
25 Correct 104 ms 126876 KB Output is correct
26 Correct 105 ms 126820 KB Output is correct
27 Correct 124 ms 131428 KB Output is correct
28 Correct 119 ms 131448 KB Output is correct
29 Correct 122 ms 131428 KB Output is correct
30 Correct 132 ms 131300 KB Output is correct
31 Correct 133 ms 131300 KB Output is correct
32 Correct 129 ms 131304 KB Output is correct
33 Correct 640 ms 213724 KB Output is correct
34 Correct 641 ms 213724 KB Output is correct
35 Correct 651 ms 213724 KB Output is correct
36 Correct 914 ms 212708 KB Output is correct
37 Correct 915 ms 212708 KB Output is correct
38 Correct 918 ms 212836 KB Output is correct
39 Correct 976 ms 213844 KB Output is correct
40 Correct 1059 ms 213464 KB Output is correct
41 Correct 978 ms 213584 KB Output is correct
42 Correct 771 ms 212712 KB Output is correct
43 Correct 782 ms 212964 KB Output is correct
44 Correct 791 ms 212832 KB Output is correct
45 Correct 783 ms 212964 KB Output is correct
46 Correct 786 ms 212800 KB Output is correct
47 Correct 799 ms 212808 KB Output is correct
48 Correct 791 ms 212832 KB Output is correct
49 Correct 792 ms 212964 KB Output is correct
50 Correct 791 ms 212832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 122468 KB Output is correct
2 Correct 81 ms 122468 KB Output is correct
3 Correct 82 ms 122468 KB Output is correct
4 Correct 82 ms 122596 KB Output is correct
5 Correct 82 ms 122540 KB Output is correct
6 Correct 82 ms 122596 KB Output is correct
7 Correct 82 ms 122596 KB Output is correct
8 Correct 83 ms 122596 KB Output is correct
9 Correct 82 ms 122596 KB Output is correct
10 Correct 82 ms 122724 KB Output is correct
11 Correct 84 ms 122596 KB Output is correct
12 Correct 82 ms 122596 KB Output is correct
13 Correct 83 ms 122624 KB Output is correct
14 Correct 83 ms 122596 KB Output is correct
15 Correct 82 ms 122596 KB Output is correct
16 Correct 87 ms 123364 KB Output is correct
17 Correct 87 ms 123364 KB Output is correct
18 Correct 88 ms 123364 KB Output is correct
19 Correct 99 ms 126948 KB Output is correct
20 Correct 102 ms 126948 KB Output is correct
21 Correct 100 ms 126948 KB Output is correct
22 Correct 104 ms 126864 KB Output is correct
23 Correct 104 ms 126820 KB Output is correct
24 Correct 101 ms 126824 KB Output is correct
25 Correct 104 ms 126876 KB Output is correct
26 Correct 105 ms 126820 KB Output is correct
27 Correct 1233 ms 397784 KB Output is correct
28 Correct 1227 ms 396236 KB Output is correct
29 Correct 1236 ms 396884 KB Output is correct
30 Correct 1219 ms 397780 KB Output is correct
31 Correct 1335 ms 394416 KB Output is correct
32 Correct 1773 ms 394468 KB Output is correct
33 Correct 1367 ms 394596 KB Output is correct
34 Correct 1458 ms 394340 KB Output is correct
35 Correct 86 ms 122596 KB Output is correct
36 Correct 977 ms 212836 KB Output is correct
37 Execution timed out 3062 ms 394436 KB Time limit exceeded
38 Halted 0 ms 0 KB -