Submission #51892

# Submission time Handle Problem Language Result Execution time Memory
51892 2018-06-22T12:13:49 Z Alexa2001 Circle selection (APIO18_circle_selection) C++17
100 / 100
1816 ms 524636 KB
#include <bits/stdc++.h>

/// 13:07

using namespace std;

typedef pair<int,int> Pair;
typedef long long ll;
const int Nmax = 3e5 + 5;

int n, i, id, R, lg;
int x[Nmax], y[Nmax], r[Nmax], ans[Nmax];
Pair ord[Nmax];
vector< vector<Pair> > v;
vector<int> start;

void rescale()
{
    int i;
    vector< vector<Pair> > nv;
    vector<Pair> q[2];

    for(auto w : v)
    {
        for(i=0; i<2; ++i) q[i].clear();

        for(auto val : w)
            if(!ans[val.second])
                q[(x[val.second] >> lg) & 1].push_back(val);

        for(i=0; i<2; ++i)
            if(q[i].size())
                nv.push_back(q[i]);
    }

    v = nv;
    start.resize(v.size());
    for(i=0; i<v.size(); ++i)
        start[i] = x[v[i][0].second] >> lg;
}

inline ll sq(int x) { return (ll)x*x; }

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

int bs(int val)
{
    int pos = 0, bit = 0;
    for(; (1<<bit) < start.size(); ++bit);

    for(--bit; bit>=0; --bit)
        if(pos + (1<<bit) < start.size() && start[pos + (1<<bit)] < val)
            pos += (1<<bit);

    if(!pos) return start[0] < val;
    return pos + 1;
}

void update_ans(int id)
{
    int pos, now, ly, ry, X;
    vector<Pair> :: iterator it;

    /*
    cout << "Writing step\n";
    cerr << v.size() << '\n';
    for(auto w : v)
    {
       cerr << "Another w:\n";
        for(auto val : w) cerr << val.first << ' ' << val.second << '\n';
    }
    */

    X = x[id] >> lg;

    ly = max(0LL, (ll)y[id] - 2 * r[id]);
    ry = min((ll)2e9, (ll)y[id] + 2 * r[id]);

    for(pos = max(0, bs(X) - 2); pos < start.size() && start[pos] <= X + 2; ++pos)
    {
        for(it = upper_bound(v[pos].begin(), v[pos].end(), make_pair(ly, 0) ); it != v[pos].end() && it->first <= ry; ++it)
        {
            now = it->second;
            if(!ans[now] && intersect(id, now))
                    ans[now] = id;
        }
    }
}

int main()
{
 //   freopen("input", "r", stdin);
  //  freopen("output", "w", stdout);

    cin.sync_with_stdio(false);

    int mnX = INT_MAX, mnY = INT_MAX;

    cin >> n;
    v.push_back({});
    for(i=1; i<=n; ++i)
    {
        cin >> x[i] >> y[i] >> r[i];
        ord[i] = {r[i], i};

        mnX = min(mnX, x[i]);
        mnY = min(mnY, y[i]);
    }

    for(i=1; i<=n; ++i)
    {
        x[i] -= mnX, y[i] -= mnY;
        v[0].push_back( {y[i], i} );
    }

    lg = 31;

    sort(v[0].begin(), v[0].end());
    sort(ord+1, ord+n+1,
         [&] (const Pair &a, const Pair &b) { if(a.first == b.first) return a.second < b.second; return a.first > b.first;} );

    for(i=1; i<=n; ++i)
    {
        id = ord[i].second;
        if(ans[id]) continue;

        while(lg && (1<<(lg-1)) >= r[id])
        {
            --lg;
            rescale();
        }

        update_ans(id);
    }

    for(i=1; i<=n; ++i) cout << ans[i] << ' ';
    return 0;
}

Compilation message

circle_selection.cpp: In function 'void rescale()':
circle_selection.cpp:38:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0; i<v.size(); ++i)
              ~^~~~~~~~~
circle_selection.cpp: In function 'int bs(int)':
circle_selection.cpp:52:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(; (1<<bit) < start.size(); ++bit);
           ~~~~~~~~~^~~~~~~~~~~~~~
circle_selection.cpp:55:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(pos + (1<<bit) < start.size() && start[pos + (1<<bit)] < val)
            ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
circle_selection.cpp: In function 'void update_ans(int)':
circle_selection.cpp:82:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(pos = max(0, bs(X) - 2); pos < start.size() && start[pos] <= X + 2; ++pos)
                                  ~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
19 Correct 6 ms 1284 KB Output is correct
20 Correct 6 ms 1420 KB Output is correct
21 Correct 6 ms 1572 KB Output is correct
22 Correct 9 ms 1876 KB Output is correct
23 Correct 8 ms 1876 KB Output is correct
24 Correct 9 ms 2260 KB Output is correct
25 Correct 15 ms 2840 KB Output is correct
26 Correct 10 ms 2840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 19596 KB Output is correct
2 Correct 217 ms 21288 KB Output is correct
3 Correct 222 ms 25572 KB Output is correct
4 Correct 201 ms 32584 KB Output is correct
5 Correct 336 ms 38632 KB Output is correct
6 Correct 490 ms 52080 KB Output is correct
7 Correct 336 ms 52080 KB Output is correct
8 Correct 358 ms 55776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 55776 KB Output is correct
2 Correct 144 ms 55776 KB Output is correct
3 Correct 520 ms 64084 KB Output is correct
4 Correct 637 ms 72164 KB Output is correct
5 Correct 556 ms 79708 KB Output is correct
6 Correct 263 ms 79708 KB Output is correct
7 Correct 101 ms 79708 KB Output is correct
8 Correct 29 ms 79708 KB Output is correct
9 Correct 548 ms 95340 KB Output is correct
10 Correct 396 ms 103624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 105708 KB Output is correct
2 Correct 1393 ms 160100 KB Output is correct
3 Correct 281 ms 160100 KB Output is correct
4 Correct 806 ms 160100 KB Output is correct
5 Correct 1141 ms 175984 KB Output is correct
6 Correct 293 ms 175984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
19 Correct 6 ms 1284 KB Output is correct
20 Correct 6 ms 1420 KB Output is correct
21 Correct 6 ms 1572 KB Output is correct
22 Correct 9 ms 1876 KB Output is correct
23 Correct 8 ms 1876 KB Output is correct
24 Correct 9 ms 2260 KB Output is correct
25 Correct 15 ms 2840 KB Output is correct
26 Correct 10 ms 2840 KB Output is correct
27 Correct 10 ms 175984 KB Output is correct
28 Correct 9 ms 175984 KB Output is correct
29 Correct 10 ms 175984 KB Output is correct
30 Correct 15 ms 175984 KB Output is correct
31 Correct 22 ms 175984 KB Output is correct
32 Correct 18 ms 175984 KB Output is correct
33 Correct 82 ms 175984 KB Output is correct
34 Correct 80 ms 175984 KB Output is correct
35 Correct 87 ms 175984 KB Output is correct
36 Correct 174 ms 175984 KB Output is correct
37 Correct 172 ms 175984 KB Output is correct
38 Correct 163 ms 175984 KB Output is correct
39 Correct 311 ms 175984 KB Output is correct
40 Correct 209 ms 175984 KB Output is correct
41 Correct 236 ms 175984 KB Output is correct
42 Correct 163 ms 175984 KB Output is correct
43 Correct 245 ms 175984 KB Output is correct
44 Correct 278 ms 175984 KB Output is correct
45 Correct 250 ms 175984 KB Output is correct
46 Correct 247 ms 178036 KB Output is correct
47 Correct 245 ms 180600 KB Output is correct
48 Correct 244 ms 185064 KB Output is correct
49 Correct 250 ms 187556 KB Output is correct
50 Correct 240 ms 188480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
19 Correct 6 ms 1284 KB Output is correct
20 Correct 6 ms 1420 KB Output is correct
21 Correct 6 ms 1572 KB Output is correct
22 Correct 9 ms 1876 KB Output is correct
23 Correct 8 ms 1876 KB Output is correct
24 Correct 9 ms 2260 KB Output is correct
25 Correct 15 ms 2840 KB Output is correct
26 Correct 10 ms 2840 KB Output is correct
27 Correct 217 ms 19596 KB Output is correct
28 Correct 217 ms 21288 KB Output is correct
29 Correct 222 ms 25572 KB Output is correct
30 Correct 201 ms 32584 KB Output is correct
31 Correct 336 ms 38632 KB Output is correct
32 Correct 490 ms 52080 KB Output is correct
33 Correct 336 ms 52080 KB Output is correct
34 Correct 358 ms 55776 KB Output is correct
35 Correct 2 ms 55776 KB Output is correct
36 Correct 144 ms 55776 KB Output is correct
37 Correct 520 ms 64084 KB Output is correct
38 Correct 637 ms 72164 KB Output is correct
39 Correct 556 ms 79708 KB Output is correct
40 Correct 263 ms 79708 KB Output is correct
41 Correct 101 ms 79708 KB Output is correct
42 Correct 29 ms 79708 KB Output is correct
43 Correct 548 ms 95340 KB Output is correct
44 Correct 396 ms 103624 KB Output is correct
45 Correct 477 ms 105708 KB Output is correct
46 Correct 1393 ms 160100 KB Output is correct
47 Correct 281 ms 160100 KB Output is correct
48 Correct 806 ms 160100 KB Output is correct
49 Correct 1141 ms 175984 KB Output is correct
50 Correct 293 ms 175984 KB Output is correct
51 Correct 10 ms 175984 KB Output is correct
52 Correct 9 ms 175984 KB Output is correct
53 Correct 10 ms 175984 KB Output is correct
54 Correct 15 ms 175984 KB Output is correct
55 Correct 22 ms 175984 KB Output is correct
56 Correct 18 ms 175984 KB Output is correct
57 Correct 82 ms 175984 KB Output is correct
58 Correct 80 ms 175984 KB Output is correct
59 Correct 87 ms 175984 KB Output is correct
60 Correct 174 ms 175984 KB Output is correct
61 Correct 172 ms 175984 KB Output is correct
62 Correct 163 ms 175984 KB Output is correct
63 Correct 311 ms 175984 KB Output is correct
64 Correct 209 ms 175984 KB Output is correct
65 Correct 236 ms 175984 KB Output is correct
66 Correct 163 ms 175984 KB Output is correct
67 Correct 245 ms 175984 KB Output is correct
68 Correct 278 ms 175984 KB Output is correct
69 Correct 250 ms 175984 KB Output is correct
70 Correct 247 ms 178036 KB Output is correct
71 Correct 245 ms 180600 KB Output is correct
72 Correct 244 ms 185064 KB Output is correct
73 Correct 250 ms 187556 KB Output is correct
74 Correct 240 ms 188480 KB Output is correct
75 Correct 261 ms 194420 KB Output is correct
76 Correct 276 ms 206196 KB Output is correct
77 Correct 287 ms 212540 KB Output is correct
78 Correct 245 ms 221180 KB Output is correct
79 Correct 288 ms 232292 KB Output is correct
80 Correct 362 ms 238908 KB Output is correct
81 Correct 697 ms 249928 KB Output is correct
82 Correct 609 ms 261200 KB Output is correct
83 Correct 573 ms 268560 KB Output is correct
84 Correct 578 ms 274264 KB Output is correct
85 Correct 576 ms 282324 KB Output is correct
86 Correct 593 ms 293124 KB Output is correct
87 Correct 531 ms 295420 KB Output is correct
88 Correct 869 ms 303536 KB Output is correct
89 Correct 826 ms 306928 KB Output is correct
90 Correct 786 ms 310252 KB Output is correct
91 Correct 764 ms 314336 KB Output is correct
92 Correct 751 ms 315536 KB Output is correct
93 Correct 1248 ms 365888 KB Output is correct
94 Correct 611 ms 365888 KB Output is correct
95 Correct 1470 ms 381300 KB Output is correct
96 Correct 1162 ms 381300 KB Output is correct
97 Correct 693 ms 381300 KB Output is correct
98 Correct 695 ms 381300 KB Output is correct
99 Correct 1361 ms 409372 KB Output is correct
100 Correct 1816 ms 423664 KB Output is correct
101 Correct 563 ms 423664 KB Output is correct
102 Correct 1278 ms 423664 KB Output is correct
103 Correct 702 ms 423664 KB Output is correct
104 Correct 1395 ms 448424 KB Output is correct
105 Correct 439 ms 448424 KB Output is correct
106 Correct 655 ms 448424 KB Output is correct
107 Correct 636 ms 448424 KB Output is correct
108 Correct 631 ms 450404 KB Output is correct
109 Correct 724 ms 458200 KB Output is correct
110 Correct 763 ms 468856 KB Output is correct
111 Correct 658 ms 473740 KB Output is correct
112 Correct 637 ms 484432 KB Output is correct
113 Correct 635 ms 488992 KB Output is correct
114 Correct 662 ms 496836 KB Output is correct
115 Correct 630 ms 504792 KB Output is correct
116 Correct 798 ms 524636 KB Output is correct