Submission #48853

# Submission time Handle Problem Language Result Execution time Memory
48853 2018-05-19T10:28:57 Z model_code Circle selection (APIO18_circle_selection) C++17
100 / 100
1673 ms 73060 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <tuple>
using namespace std;
typedef long long ll;
const int maxn=5e5+5;
ll x[maxn],y[maxn],r[maxn];
int n;
void read()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld %lld %lld",&x[i],&y[i],&r[i]);
}
bool inter(int i,int j)
{
    ll dx=x[i]-x[j],dy=y[i]-y[j];
    ll dd=dx*dx+dy*dy,rr=(r[i]+r[j])*(r[i]+r[j]);
    return dd<=rr;
}
struct H
{
    typedef pair<ll,int> P;
    int log2_unit;
    vector<vector<P>> v;
    void init()
    {
        log2_unit=0;
        for(int i=1;i<=n;i++) log2_unit=max(log2_unit,(int)__lg(x[i])+1);
        v.resize(1);
        for(int i=1;i<=n;i++) v[0].push_back({y[i],i});
        sort(v[0].begin(),v[0].end());
    }
    void rescale(const bitset<maxn> &del)
    {
        log2_unit--;
        vector<vector<P>> nv;
        for(const auto &d:v)
        {
            vector<P> cur[2];
            for(const P &p:d) if(!del[p.second])
                cur[(x[p.second]>>log2_unit)&1].push_back(p);
            for(int i=0;i<2;i++) if(cur[i].size())
            {
                nv.push_back({});
                nv.back().swap(cur[i]);
            }
        }
        v.swap(nv);
    }
    void ask(int i,bitset<maxn> &del,int *ans)
    {
        int xl=lower_bound(v.begin(),v.end(),(x[i]>>log2_unit)-2,
                [&](const vector<P> &a,const ll &b){return (x[a[0].second]>>log2_unit) < b;})-v.begin();
        int xr=xl;while(xr<(int)v.size() && \
                (x[v[xr][0].second]>>log2_unit) <= (x[i]>>log2_unit)+2) xr++;
        for(int m=xl;m<xr;m++)
        {
            for(auto it=lower_bound(v[m].begin(),v[m].end(),P{y[i]-2*r[i],0});
                    it!=v[m].end() && it->first <= y[i]+2*r[i];it++)
                if(!del[it->second] && inter(i,it->second))
                    del[it->second]=1,ans[it->second]=i;
        }
    }
} helper;
int ori[maxn],ans[maxn];
void build()
{
    ll lox=*min_element(x+1,x+n+1);
    for(int i=1;i<=n;i++) x[i]=x[i]-lox+1;
    ll loy=*min_element(y+1,y+n+1);
    for(int i=1;i<=n;i++) y[i]=y[i]-loy+1;

    iota(ori+1,ori+n+1,1);
    sort(ori+1,ori+n+1,[&](int i,int j){return tie(r[i],j) > tie(r[j],i);});

    vector<ll> xx(n+1),yy(n+1),rr(n+1);
    for(int i=1;i<=n;i++) xx[i]=x[ori[i]],yy[i]=y[ori[i]],rr[i]=r[ori[i]];
    for(int i=1;i<=n;i++) x[i]=xx[i],y[i]=yy[i],r[i]=rr[i];
}
void sol()
{
    helper.init();
    bitset<maxn> del;
    for(int i=1;i<=n;i++) if(!del[i])
    {
        del[i]=1;ans[i]=i;
        while(r[i]<=(1LL<<helper.log2_unit)/2) helper.rescale(del);
        helper.ask(i,del,ans);
    }

    vector<int> v(n+1);
    for(int i=1;i<=n;i++) v[ori[i]]=ori[ans[i]];
    for(int i=1;i<=n;i++) ans[i]=v[i];
    for(int i=1;i<=n;i++) printf("%d%c",ans[i]," \n"[i==n]);
}
int main()
{
    read();
    build();
    sol();
    return 0;
}

Compilation message

circle_selection.cpp: In function 'void read()':
circle_selection.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
circle_selection.cpp:15:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) scanf("%lld %lld %lld",&x[i],&y[i],&r[i]);
                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 688 KB Output is correct
14 Correct 2 ms 688 KB Output is correct
15 Correct 2 ms 688 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 3 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
19 Correct 6 ms 1024 KB Output is correct
20 Correct 6 ms 1024 KB Output is correct
21 Correct 6 ms 1036 KB Output is correct
22 Correct 10 ms 1344 KB Output is correct
23 Correct 8 ms 1344 KB Output is correct
24 Correct 10 ms 1416 KB Output is correct
25 Correct 12 ms 1592 KB Output is correct
26 Correct 12 ms 1592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 262 ms 21812 KB Output is correct
2 Correct 261 ms 24780 KB Output is correct
3 Correct 250 ms 24780 KB Output is correct
4 Correct 247 ms 24780 KB Output is correct
5 Correct 300 ms 26164 KB Output is correct
6 Correct 515 ms 33428 KB Output is correct
7 Correct 386 ms 33428 KB Output is correct
8 Correct 408 ms 33428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 33428 KB Output is correct
2 Correct 182 ms 33428 KB Output is correct
3 Correct 712 ms 33428 KB Output is correct
4 Correct 758 ms 33428 KB Output is correct
5 Correct 559 ms 33428 KB Output is correct
6 Correct 251 ms 33428 KB Output is correct
7 Correct 127 ms 33428 KB Output is correct
8 Correct 27 ms 33428 KB Output is correct
9 Correct 588 ms 33428 KB Output is correct
10 Correct 598 ms 33428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 790 ms 33428 KB Output is correct
2 Correct 1673 ms 73060 KB Output is correct
3 Correct 393 ms 73060 KB Output is correct
4 Correct 1256 ms 73060 KB Output is correct
5 Correct 1267 ms 73060 KB Output is correct
6 Correct 309 ms 73060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 688 KB Output is correct
14 Correct 2 ms 688 KB Output is correct
15 Correct 2 ms 688 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 3 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
19 Correct 6 ms 1024 KB Output is correct
20 Correct 6 ms 1024 KB Output is correct
21 Correct 6 ms 1036 KB Output is correct
22 Correct 10 ms 1344 KB Output is correct
23 Correct 8 ms 1344 KB Output is correct
24 Correct 10 ms 1416 KB Output is correct
25 Correct 12 ms 1592 KB Output is correct
26 Correct 12 ms 1592 KB Output is correct
27 Correct 11 ms 73060 KB Output is correct
28 Correct 11 ms 73060 KB Output is correct
29 Correct 11 ms 73060 KB Output is correct
30 Correct 17 ms 73060 KB Output is correct
31 Correct 20 ms 73060 KB Output is correct
32 Correct 18 ms 73060 KB Output is correct
33 Correct 100 ms 73060 KB Output is correct
34 Correct 102 ms 73060 KB Output is correct
35 Correct 115 ms 73060 KB Output is correct
36 Correct 236 ms 73060 KB Output is correct
37 Correct 216 ms 73060 KB Output is correct
38 Correct 203 ms 73060 KB Output is correct
39 Correct 284 ms 73060 KB Output is correct
40 Correct 287 ms 73060 KB Output is correct
41 Correct 336 ms 73060 KB Output is correct
42 Correct 104 ms 73060 KB Output is correct
43 Correct 400 ms 73060 KB Output is correct
44 Correct 321 ms 73060 KB Output is correct
45 Correct 336 ms 73060 KB Output is correct
46 Correct 318 ms 73060 KB Output is correct
47 Correct 255 ms 73060 KB Output is correct
48 Correct 253 ms 73060 KB Output is correct
49 Correct 296 ms 73060 KB Output is correct
50 Correct 318 ms 73060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 688 KB Output is correct
14 Correct 2 ms 688 KB Output is correct
15 Correct 2 ms 688 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 3 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
19 Correct 6 ms 1024 KB Output is correct
20 Correct 6 ms 1024 KB Output is correct
21 Correct 6 ms 1036 KB Output is correct
22 Correct 10 ms 1344 KB Output is correct
23 Correct 8 ms 1344 KB Output is correct
24 Correct 10 ms 1416 KB Output is correct
25 Correct 12 ms 1592 KB Output is correct
26 Correct 12 ms 1592 KB Output is correct
27 Correct 262 ms 21812 KB Output is correct
28 Correct 261 ms 24780 KB Output is correct
29 Correct 250 ms 24780 KB Output is correct
30 Correct 247 ms 24780 KB Output is correct
31 Correct 300 ms 26164 KB Output is correct
32 Correct 515 ms 33428 KB Output is correct
33 Correct 386 ms 33428 KB Output is correct
34 Correct 408 ms 33428 KB Output is correct
35 Correct 2 ms 33428 KB Output is correct
36 Correct 182 ms 33428 KB Output is correct
37 Correct 712 ms 33428 KB Output is correct
38 Correct 758 ms 33428 KB Output is correct
39 Correct 559 ms 33428 KB Output is correct
40 Correct 251 ms 33428 KB Output is correct
41 Correct 127 ms 33428 KB Output is correct
42 Correct 27 ms 33428 KB Output is correct
43 Correct 588 ms 33428 KB Output is correct
44 Correct 598 ms 33428 KB Output is correct
45 Correct 790 ms 33428 KB Output is correct
46 Correct 1673 ms 73060 KB Output is correct
47 Correct 393 ms 73060 KB Output is correct
48 Correct 1256 ms 73060 KB Output is correct
49 Correct 1267 ms 73060 KB Output is correct
50 Correct 309 ms 73060 KB Output is correct
51 Correct 11 ms 73060 KB Output is correct
52 Correct 11 ms 73060 KB Output is correct
53 Correct 11 ms 73060 KB Output is correct
54 Correct 17 ms 73060 KB Output is correct
55 Correct 20 ms 73060 KB Output is correct
56 Correct 18 ms 73060 KB Output is correct
57 Correct 100 ms 73060 KB Output is correct
58 Correct 102 ms 73060 KB Output is correct
59 Correct 115 ms 73060 KB Output is correct
60 Correct 236 ms 73060 KB Output is correct
61 Correct 216 ms 73060 KB Output is correct
62 Correct 203 ms 73060 KB Output is correct
63 Correct 284 ms 73060 KB Output is correct
64 Correct 287 ms 73060 KB Output is correct
65 Correct 336 ms 73060 KB Output is correct
66 Correct 104 ms 73060 KB Output is correct
67 Correct 400 ms 73060 KB Output is correct
68 Correct 321 ms 73060 KB Output is correct
69 Correct 336 ms 73060 KB Output is correct
70 Correct 318 ms 73060 KB Output is correct
71 Correct 255 ms 73060 KB Output is correct
72 Correct 253 ms 73060 KB Output is correct
73 Correct 296 ms 73060 KB Output is correct
74 Correct 318 ms 73060 KB Output is correct
75 Correct 340 ms 73060 KB Output is correct
76 Correct 359 ms 73060 KB Output is correct
77 Correct 329 ms 73060 KB Output is correct
78 Correct 327 ms 73060 KB Output is correct
79 Correct 413 ms 73060 KB Output is correct
80 Correct 325 ms 73060 KB Output is correct
81 Correct 913 ms 73060 KB Output is correct
82 Correct 844 ms 73060 KB Output is correct
83 Correct 877 ms 73060 KB Output is correct
84 Correct 627 ms 73060 KB Output is correct
85 Correct 639 ms 73060 KB Output is correct
86 Correct 748 ms 73060 KB Output is correct
87 Correct 574 ms 73060 KB Output is correct
88 Correct 1022 ms 73060 KB Output is correct
89 Correct 1228 ms 73060 KB Output is correct
90 Correct 1530 ms 73060 KB Output is correct
91 Correct 1401 ms 73060 KB Output is correct
92 Correct 1154 ms 73060 KB Output is correct
93 Correct 1325 ms 73060 KB Output is correct
94 Correct 428 ms 73060 KB Output is correct
95 Correct 1306 ms 73060 KB Output is correct
96 Correct 1221 ms 73060 KB Output is correct
97 Correct 582 ms 73060 KB Output is correct
98 Correct 617 ms 73060 KB Output is correct
99 Correct 1432 ms 73060 KB Output is correct
100 Correct 1555 ms 73060 KB Output is correct
101 Correct 636 ms 73060 KB Output is correct
102 Correct 1383 ms 73060 KB Output is correct
103 Correct 508 ms 73060 KB Output is correct
104 Correct 1322 ms 73060 KB Output is correct
105 Correct 358 ms 73060 KB Output is correct
106 Correct 819 ms 73060 KB Output is correct
107 Correct 790 ms 73060 KB Output is correct
108 Correct 753 ms 73060 KB Output is correct
109 Correct 971 ms 73060 KB Output is correct
110 Correct 916 ms 73060 KB Output is correct
111 Correct 827 ms 73060 KB Output is correct
112 Correct 1095 ms 73060 KB Output is correct
113 Correct 898 ms 73060 KB Output is correct
114 Correct 859 ms 73060 KB Output is correct
115 Correct 854 ms 73060 KB Output is correct
116 Correct 963 ms 73060 KB Output is correct