Submission #568555

# Submission time Handle Problem Language Result Execution time Memory
568555 2022-05-25T16:49:34 Z piOOE Circle selection (APIO18_circle_selection) C++17
100 / 100
2145 ms 42972 KB
//#define _GLIBCXX_DEBUG
 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
 
using namespace std;
 
//#include <ext/pb_ds/assoc_container.hpp>
//
//using namespace __gnu_pbds;
//
//template<typename T>
//using ordered_set = tree<T, null_type, less < T>, rb_tree_tag, tree_order_statistics_node_update>;
 
template<typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
 
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
 
#define trace(x) cout << #x << ": " << (x) << endl;
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define uniq(x) x.resize(unique(all(x)) - begin(x))
#define sz(s) ((int) size(s))
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define int128 __int128
#define pb push_back
#define popb pop_back
#define eb emplace_back
#define fi first
#define se second
#define itn int
 
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
 
 
template<typename T>
bool ckmn(T &x, T y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
 
template<typename T>
bool ckmx(T &x, T y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
 
int bit(int x, int b) {
    return (x >> b) & 1;
}
 
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
 
 
const ll infL = 3e18;
const int infI = 1000000000 + 7;
const int infM = 0x3f3f3f3f; //a little bigger than 1e9
const ll infML = 0x3f3f3f3f3f3f3f3fLL; //4.5e18
const int N = 300002;
const int mod = 998244353;
const ld eps = 1e-9;
 
int x[N], y[N], r[N], ans[N];
 
auto inter = [](int i, int j) {
    return ((ll) x[i] - x[j]) * (x[i] - x[j]) + ((ll) y[i] - y[j]) * (y[i] - y[j]) <=
           (r[i] + r[j]) * ((ll) r[i] + r[j]);
};
 
int R;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> r[i];
    }
    memset(ans, -1, sizeof(ans));
    vector<int> ordd(n);
    iota(all(ordd), 0);
    sort(all(ordd), [](int i, int j) {
        if (r[i] != r[j]) return r[i] > r[j];
        return i < j;
    });
    R = infI * 2;
    vector<vector<pair<int, int>>> points;
    vector<int> ordx(n), ordy(n), scl_x, pos(n);
    iota(all(ordx), 0);
    iota(all(ordy), 0);
    sort(all(ordx), [](int i, int j) {
        return x[i] < x[j];
    });
    sort(all(ordy), [](int i, int j) {
        return y[i] < y[j];
    });
 
    auto rescale = [&](int rr) {
        R = rr;
        scl_x.clear();
        for (int i = 0; i < n; ++i) {
            int nw = x[ordx[i]] / R;
            if (scl_x.empty() || scl_x.back() != nw) {
                scl_x.push_back(nw);
            }
            pos[ordx[i]] = sz(scl_x) - 1;
        }
        points.clear();
        points.resize(sz(scl_x));
        for (int i = 0; i < sz(points); ++i) assert(points[i].empty());
        for (int i: ordy) {
            points[pos[i]].eb(y[i] / R, i);
        }
    };
    for (int i: ordd) {
        if (R >= r[i] * 2) {
            rescale(r[i]);
        }
        if (ans[i] == -1) {
            int lx = lower_bound(all(scl_x), x[i] / R - 2) - begin(scl_x), rx =
                    upper_bound(all(scl_x), x[i] / R + 2) - begin(scl_x);
            for (int f = lx; f < rx; ++f) {
                int ly = lower_bound(all(points[f]), mp(y[i] / R - 2, -1)) - begin(points[f]), ry =
                        upper_bound(all(points[f]), mp(y[i] / R + 3, -1)) - begin(points[f]);
                for (int j = ly; j < ry; ++j) {
                    if (ans[points[f][j].second] == -1 && inter(i, points[f][j].second)) {
                        ans[points[f][j].second] = i;
                    }
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << ans[i] + 1 << " ";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1480 KB Output is correct
6 Correct 2 ms 1492 KB Output is correct
7 Correct 2 ms 1480 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 2 ms 1488 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 2 ms 1484 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1492 KB Output is correct
16 Correct 2 ms 1620 KB Output is correct
17 Correct 2 ms 1624 KB Output is correct
18 Correct 3 ms 1620 KB Output is correct
19 Correct 6 ms 1984 KB Output is correct
20 Correct 5 ms 1884 KB Output is correct
21 Correct 6 ms 1876 KB Output is correct
22 Correct 10 ms 2260 KB Output is correct
23 Correct 11 ms 2220 KB Output is correct
24 Correct 14 ms 2332 KB Output is correct
25 Correct 9 ms 2260 KB Output is correct
26 Correct 10 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 519 ms 35520 KB Output is correct
2 Correct 483 ms 37868 KB Output is correct
3 Correct 494 ms 37728 KB Output is correct
4 Correct 411 ms 34968 KB Output is correct
5 Correct 391 ms 28344 KB Output is correct
6 Correct 675 ms 38572 KB Output is correct
7 Correct 572 ms 37152 KB Output is correct
8 Correct 577 ms 37120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 354 ms 15424 KB Output is correct
3 Correct 1712 ms 42600 KB Output is correct
4 Correct 1729 ms 42684 KB Output is correct
5 Correct 1406 ms 41612 KB Output is correct
6 Correct 495 ms 22928 KB Output is correct
7 Correct 224 ms 12972 KB Output is correct
8 Correct 37 ms 4368 KB Output is correct
9 Correct 1334 ms 42396 KB Output is correct
10 Correct 1342 ms 42972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 404 ms 26496 KB Output is correct
2 Correct 442 ms 36308 KB Output is correct
3 Correct 240 ms 23116 KB Output is correct
4 Correct 451 ms 35396 KB Output is correct
5 Correct 460 ms 36308 KB Output is correct
6 Correct 240 ms 22308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1480 KB Output is correct
6 Correct 2 ms 1492 KB Output is correct
7 Correct 2 ms 1480 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 2 ms 1488 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 2 ms 1484 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1492 KB Output is correct
16 Correct 2 ms 1620 KB Output is correct
17 Correct 2 ms 1624 KB Output is correct
18 Correct 3 ms 1620 KB Output is correct
19 Correct 6 ms 1984 KB Output is correct
20 Correct 5 ms 1884 KB Output is correct
21 Correct 6 ms 1876 KB Output is correct
22 Correct 10 ms 2260 KB Output is correct
23 Correct 11 ms 2220 KB Output is correct
24 Correct 14 ms 2332 KB Output is correct
25 Correct 9 ms 2260 KB Output is correct
26 Correct 10 ms 2260 KB Output is correct
27 Correct 13 ms 2768 KB Output is correct
28 Correct 13 ms 2404 KB Output is correct
29 Correct 16 ms 2652 KB Output is correct
30 Correct 23 ms 2908 KB Output is correct
31 Correct 28 ms 3036 KB Output is correct
32 Correct 31 ms 3060 KB Output is correct
33 Correct 160 ms 10560 KB Output is correct
34 Correct 155 ms 12860 KB Output is correct
35 Correct 160 ms 11908 KB Output is correct
36 Correct 338 ms 15512 KB Output is correct
37 Correct 409 ms 15604 KB Output is correct
38 Correct 398 ms 15664 KB Output is correct
39 Correct 217 ms 7228 KB Output is correct
40 Correct 195 ms 7200 KB Output is correct
41 Correct 187 ms 7184 KB Output is correct
42 Correct 77 ms 7856 KB Output is correct
43 Correct 137 ms 13016 KB Output is correct
44 Correct 114 ms 13068 KB Output is correct
45 Correct 117 ms 13060 KB Output is correct
46 Correct 122 ms 13064 KB Output is correct
47 Correct 138 ms 13108 KB Output is correct
48 Correct 117 ms 13136 KB Output is correct
49 Correct 100 ms 13068 KB Output is correct
50 Correct 110 ms 13036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1480 KB Output is correct
6 Correct 2 ms 1492 KB Output is correct
7 Correct 2 ms 1480 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 2 ms 1488 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 2 ms 1484 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1492 KB Output is correct
16 Correct 2 ms 1620 KB Output is correct
17 Correct 2 ms 1624 KB Output is correct
18 Correct 3 ms 1620 KB Output is correct
19 Correct 6 ms 1984 KB Output is correct
20 Correct 5 ms 1884 KB Output is correct
21 Correct 6 ms 1876 KB Output is correct
22 Correct 10 ms 2260 KB Output is correct
23 Correct 11 ms 2220 KB Output is correct
24 Correct 14 ms 2332 KB Output is correct
25 Correct 9 ms 2260 KB Output is correct
26 Correct 10 ms 2260 KB Output is correct
27 Correct 519 ms 35520 KB Output is correct
28 Correct 483 ms 37868 KB Output is correct
29 Correct 494 ms 37728 KB Output is correct
30 Correct 411 ms 34968 KB Output is correct
31 Correct 391 ms 28344 KB Output is correct
32 Correct 675 ms 38572 KB Output is correct
33 Correct 572 ms 37152 KB Output is correct
34 Correct 577 ms 37120 KB Output is correct
35 Correct 1 ms 1492 KB Output is correct
36 Correct 354 ms 15424 KB Output is correct
37 Correct 1712 ms 42600 KB Output is correct
38 Correct 1729 ms 42684 KB Output is correct
39 Correct 1406 ms 41612 KB Output is correct
40 Correct 495 ms 22928 KB Output is correct
41 Correct 224 ms 12972 KB Output is correct
42 Correct 37 ms 4368 KB Output is correct
43 Correct 1334 ms 42396 KB Output is correct
44 Correct 1342 ms 42972 KB Output is correct
45 Correct 404 ms 26496 KB Output is correct
46 Correct 442 ms 36308 KB Output is correct
47 Correct 240 ms 23116 KB Output is correct
48 Correct 451 ms 35396 KB Output is correct
49 Correct 460 ms 36308 KB Output is correct
50 Correct 240 ms 22308 KB Output is correct
51 Correct 13 ms 2768 KB Output is correct
52 Correct 13 ms 2404 KB Output is correct
53 Correct 16 ms 2652 KB Output is correct
54 Correct 23 ms 2908 KB Output is correct
55 Correct 28 ms 3036 KB Output is correct
56 Correct 31 ms 3060 KB Output is correct
57 Correct 160 ms 10560 KB Output is correct
58 Correct 155 ms 12860 KB Output is correct
59 Correct 160 ms 11908 KB Output is correct
60 Correct 338 ms 15512 KB Output is correct
61 Correct 409 ms 15604 KB Output is correct
62 Correct 398 ms 15664 KB Output is correct
63 Correct 217 ms 7228 KB Output is correct
64 Correct 195 ms 7200 KB Output is correct
65 Correct 187 ms 7184 KB Output is correct
66 Correct 77 ms 7856 KB Output is correct
67 Correct 137 ms 13016 KB Output is correct
68 Correct 114 ms 13068 KB Output is correct
69 Correct 117 ms 13060 KB Output is correct
70 Correct 122 ms 13064 KB Output is correct
71 Correct 138 ms 13108 KB Output is correct
72 Correct 117 ms 13136 KB Output is correct
73 Correct 100 ms 13068 KB Output is correct
74 Correct 110 ms 13036 KB Output is correct
75 Correct 739 ms 38104 KB Output is correct
76 Correct 753 ms 34196 KB Output is correct
77 Correct 652 ms 31220 KB Output is correct
78 Correct 652 ms 33788 KB Output is correct
79 Correct 811 ms 37736 KB Output is correct
80 Correct 605 ms 30868 KB Output is correct
81 Correct 1967 ms 42316 KB Output is correct
82 Correct 2107 ms 42276 KB Output is correct
83 Correct 2145 ms 42204 KB Output is correct
84 Correct 1984 ms 42676 KB Output is correct
85 Correct 2052 ms 42280 KB Output is correct
86 Correct 1979 ms 42336 KB Output is correct
87 Correct 1683 ms 42088 KB Output is correct
88 Correct 787 ms 19592 KB Output is correct
89 Correct 737 ms 19568 KB Output is correct
90 Correct 863 ms 19580 KB Output is correct
91 Correct 762 ms 19668 KB Output is correct
92 Correct 918 ms 19592 KB Output is correct
93 Correct 941 ms 41356 KB Output is correct
94 Correct 491 ms 23896 KB Output is correct
95 Correct 941 ms 41260 KB Output is correct
96 Correct 1083 ms 41300 KB Output is correct
97 Correct 593 ms 21800 KB Output is correct
98 Correct 971 ms 41148 KB Output is correct
99 Correct 1103 ms 41496 KB Output is correct
100 Correct 709 ms 41120 KB Output is correct
101 Correct 1046 ms 40904 KB Output is correct
102 Correct 1185 ms 41392 KB Output is correct
103 Correct 681 ms 22748 KB Output is correct
104 Correct 995 ms 41224 KB Output is correct
105 Correct 239 ms 21248 KB Output is correct
106 Correct 416 ms 33120 KB Output is correct
107 Correct 365 ms 33252 KB Output is correct
108 Correct 409 ms 33244 KB Output is correct
109 Correct 390 ms 33216 KB Output is correct
110 Correct 358 ms 33104 KB Output is correct
111 Correct 351 ms 33268 KB Output is correct
112 Correct 388 ms 33232 KB Output is correct
113 Correct 360 ms 33200 KB Output is correct
114 Correct 371 ms 33124 KB Output is correct
115 Correct 357 ms 33212 KB Output is correct
116 Correct 346 ms 35732 KB Output is correct