답안 #500414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500414 2021-12-31T00:00:09 Z dimash241 원 고르기 (APIO18_circle_selection) C++17
100 / 100
976 ms 74068 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]
   14 |     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]
   15 |     for(int i=1;i<=n;i++) scanf("%lld %lld %lld",&x[i],&y[i],&r[i]);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 276 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 292 KB Output is correct
15 Correct 0 ms 296 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 2 ms 436 KB Output is correct
19 Correct 5 ms 816 KB Output is correct
20 Correct 6 ms 816 KB Output is correct
21 Correct 5 ms 808 KB Output is correct
22 Correct 6 ms 1104 KB Output is correct
23 Correct 6 ms 892 KB Output is correct
24 Correct 7 ms 1176 KB Output is correct
25 Correct 8 ms 1384 KB Output is correct
26 Correct 6 ms 1200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 28144 KB Output is correct
2 Correct 185 ms 31132 KB Output is correct
3 Correct 207 ms 30024 KB Output is correct
4 Correct 175 ms 28164 KB Output is correct
5 Correct 295 ms 30616 KB Output is correct
6 Correct 448 ms 35356 KB Output is correct
7 Correct 276 ms 30796 KB Output is correct
8 Correct 320 ms 34456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 153 ms 11444 KB Output is correct
3 Correct 521 ms 37672 KB Output is correct
4 Correct 508 ms 37712 KB Output is correct
5 Correct 434 ms 36872 KB Output is correct
6 Correct 225 ms 19120 KB Output is correct
7 Correct 96 ms 9856 KB Output is correct
8 Correct 20 ms 2716 KB Output is correct
9 Correct 612 ms 36688 KB Output is correct
10 Correct 403 ms 34916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 526 ms 35708 KB Output is correct
2 Correct 963 ms 74068 KB Output is correct
3 Correct 281 ms 31868 KB Output is correct
4 Correct 728 ms 56860 KB Output is correct
5 Correct 756 ms 65200 KB Output is correct
6 Correct 235 ms 35964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 276 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 292 KB Output is correct
15 Correct 0 ms 296 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 2 ms 436 KB Output is correct
19 Correct 5 ms 816 KB Output is correct
20 Correct 6 ms 816 KB Output is correct
21 Correct 5 ms 808 KB Output is correct
22 Correct 6 ms 1104 KB Output is correct
23 Correct 6 ms 892 KB Output is correct
24 Correct 7 ms 1176 KB Output is correct
25 Correct 8 ms 1384 KB Output is correct
26 Correct 6 ms 1200 KB Output is correct
27 Correct 6 ms 1332 KB Output is correct
28 Correct 6 ms 1324 KB Output is correct
29 Correct 6 ms 1248 KB Output is correct
30 Correct 13 ms 1604 KB Output is correct
31 Correct 12 ms 1908 KB Output is correct
32 Correct 12 ms 1936 KB Output is correct
33 Correct 62 ms 9780 KB Output is correct
34 Correct 62 ms 9716 KB Output is correct
35 Correct 63 ms 10516 KB Output is correct
36 Correct 149 ms 14604 KB Output is correct
37 Correct 147 ms 14384 KB Output is correct
38 Correct 139 ms 12492 KB Output is correct
39 Correct 201 ms 11740 KB Output is correct
40 Correct 186 ms 11944 KB Output is correct
41 Correct 216 ms 11788 KB Output is correct
42 Correct 79 ms 10180 KB Output is correct
43 Correct 168 ms 20780 KB Output is correct
44 Correct 175 ms 20768 KB Output is correct
45 Correct 169 ms 20716 KB Output is correct
46 Correct 173 ms 20716 KB Output is correct
47 Correct 181 ms 20696 KB Output is correct
48 Correct 183 ms 20784 KB Output is correct
49 Correct 169 ms 20772 KB Output is correct
50 Correct 173 ms 20724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 276 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 292 KB Output is correct
15 Correct 0 ms 296 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 2 ms 436 KB Output is correct
19 Correct 5 ms 816 KB Output is correct
20 Correct 6 ms 816 KB Output is correct
21 Correct 5 ms 808 KB Output is correct
22 Correct 6 ms 1104 KB Output is correct
23 Correct 6 ms 892 KB Output is correct
24 Correct 7 ms 1176 KB Output is correct
25 Correct 8 ms 1384 KB Output is correct
26 Correct 6 ms 1200 KB Output is correct
27 Correct 207 ms 28144 KB Output is correct
28 Correct 185 ms 31132 KB Output is correct
29 Correct 207 ms 30024 KB Output is correct
30 Correct 175 ms 28164 KB Output is correct
31 Correct 295 ms 30616 KB Output is correct
32 Correct 448 ms 35356 KB Output is correct
33 Correct 276 ms 30796 KB Output is correct
34 Correct 320 ms 34456 KB Output is correct
35 Correct 1 ms 292 KB Output is correct
36 Correct 153 ms 11444 KB Output is correct
37 Correct 521 ms 37672 KB Output is correct
38 Correct 508 ms 37712 KB Output is correct
39 Correct 434 ms 36872 KB Output is correct
40 Correct 225 ms 19120 KB Output is correct
41 Correct 96 ms 9856 KB Output is correct
42 Correct 20 ms 2716 KB Output is correct
43 Correct 612 ms 36688 KB Output is correct
44 Correct 403 ms 34916 KB Output is correct
45 Correct 526 ms 35708 KB Output is correct
46 Correct 963 ms 74068 KB Output is correct
47 Correct 281 ms 31868 KB Output is correct
48 Correct 728 ms 56860 KB Output is correct
49 Correct 756 ms 65200 KB Output is correct
50 Correct 235 ms 35964 KB Output is correct
51 Correct 6 ms 1332 KB Output is correct
52 Correct 6 ms 1324 KB Output is correct
53 Correct 6 ms 1248 KB Output is correct
54 Correct 13 ms 1604 KB Output is correct
55 Correct 12 ms 1908 KB Output is correct
56 Correct 12 ms 1936 KB Output is correct
57 Correct 62 ms 9780 KB Output is correct
58 Correct 62 ms 9716 KB Output is correct
59 Correct 63 ms 10516 KB Output is correct
60 Correct 149 ms 14604 KB Output is correct
61 Correct 147 ms 14384 KB Output is correct
62 Correct 139 ms 12492 KB Output is correct
63 Correct 201 ms 11740 KB Output is correct
64 Correct 186 ms 11944 KB Output is correct
65 Correct 216 ms 11788 KB Output is correct
66 Correct 79 ms 10180 KB Output is correct
67 Correct 168 ms 20780 KB Output is correct
68 Correct 175 ms 20768 KB Output is correct
69 Correct 169 ms 20716 KB Output is correct
70 Correct 173 ms 20716 KB Output is correct
71 Correct 181 ms 20696 KB Output is correct
72 Correct 183 ms 20784 KB Output is correct
73 Correct 169 ms 20772 KB Output is correct
74 Correct 173 ms 20724 KB Output is correct
75 Correct 254 ms 30964 KB Output is correct
76 Correct 213 ms 33076 KB Output is correct
77 Correct 196 ms 29752 KB Output is correct
78 Correct 187 ms 29944 KB Output is correct
79 Correct 242 ms 33388 KB Output is correct
80 Correct 193 ms 29900 KB Output is correct
81 Correct 493 ms 35892 KB Output is correct
82 Correct 526 ms 37004 KB Output is correct
83 Correct 516 ms 38376 KB Output is correct
84 Correct 465 ms 38324 KB Output is correct
85 Correct 479 ms 34956 KB Output is correct
86 Correct 505 ms 37324 KB Output is correct
87 Correct 426 ms 34008 KB Output is correct
88 Correct 848 ms 40144 KB Output is correct
89 Correct 976 ms 40200 KB Output is correct
90 Correct 854 ms 40116 KB Output is correct
91 Correct 872 ms 40112 KB Output is correct
92 Correct 825 ms 40060 KB Output is correct
93 Correct 770 ms 56632 KB Output is correct
94 Correct 261 ms 28240 KB Output is correct
95 Correct 764 ms 64076 KB Output is correct
96 Correct 710 ms 56608 KB Output is correct
97 Correct 408 ms 32316 KB Output is correct
98 Correct 444 ms 39100 KB Output is correct
99 Correct 823 ms 59828 KB Output is correct
100 Correct 881 ms 62192 KB Output is correct
101 Correct 433 ms 34744 KB Output is correct
102 Correct 673 ms 56444 KB Output is correct
103 Correct 389 ms 32652 KB Output is correct
104 Correct 801 ms 66164 KB Output is correct
105 Correct 300 ms 32036 KB Output is correct
106 Correct 595 ms 52320 KB Output is correct
107 Correct 581 ms 52252 KB Output is correct
108 Correct 573 ms 50980 KB Output is correct
109 Correct 584 ms 52408 KB Output is correct
110 Correct 585 ms 52364 KB Output is correct
111 Correct 591 ms 52128 KB Output is correct
112 Correct 609 ms 52176 KB Output is correct
113 Correct 586 ms 50956 KB Output is correct
114 Correct 569 ms 50908 KB Output is correct
115 Correct 602 ms 52420 KB Output is correct
116 Correct 626 ms 61756 KB Output is correct