Submission #49664

# Submission time Handle Problem Language Result Execution time Memory
49664 2018-06-01T18:49:47 Z gs14004 Circle selection (APIO18_circle_selection) C++17
100 / 100
3570 ms 231144 KB
#include<cstdio>
#include<algorithm>
#define N_ 301000
using namespace std;
struct Circle {
    int x, y, r, num;
    bool operator<(const Circle &p)const {
        return r != p.r ? r > p.r:num < p.num;
    }
}w[N_];
int n, Res[N_], INF = 1e9, U[22][1<<21], UF[N_*4][22];
struct point {
    int x, y, num;
    bool operator<(const point &p)const {
        return x != p.x ? x < p.x : y < p.y;
    }
}P[N_*4];
bool Intersect(int a, int b) {
    long long dx = w[a].x - w[b].x, dy = w[a].y - w[b].y, dr = w[a].r + w[b].r;
    if (dx*dx + dy*dy <= dr*dr)return true;
    return false;
}
void Chk(int a, int b) {
    if (Res[w[b].num])return;
    if (Intersect(a, b))Res[w[b].num] = w[a].num;
}
int Find(int a, int pv) {
    if (a == UF[a][pv])return a;
    return UF[a][pv] = Find(UF[a][pv], pv);
}
void Del(int a, int pv) {
    UF[a][pv] = Find(UF[a + 1][pv], pv);
}
void Do2(int a, int nd, int pv) {
    int bb;
    int y1 = w[a].y - w[a].r, y2 = w[a].y + w[a].r;
    if (pv >= 3) {
        int b = (nd << pv), e = ((nd + 1) << pv) - 1;
        bb = e + 1;
        int mid;
        while (b <= e) {
            mid = (b + e) >> 1;
            if (P[U[pv][mid]].y >= y1) {
                bb = mid;
                e = mid - 1;
            }
            else b = mid + 1;
        }
    }
    else {
        bb = (nd << pv);
    }
    int e = ((nd + 1) << pv);
    while (1) {
        bb = Find(bb, pv);
        if (bb >= e)break;
        int t = U[pv][bb];
        if (P[t].y > y2)break;
        int tt = P[t].num;
        Chk(a, tt);
        if (Res[w[tt].num])Del(bb, pv);
        bb++;
    }
}
void Do(int a, int b, int e) {
    int pv = 0;
    while (b <= e) {
        if (b & 1) {
            Do2(a, b, pv);
        }
        if (!(e & 1)) {
            Do2(a, e, pv);
        }
        b = (b + 1) >> 1;
        e = (e - 1) >> 1;
        pv++;
    }
}
void Go(int a, int bx, int ex, int by, int ey) {
    point tp = { bx,-INF * 2 - 1, -1 };
    int b = lower_bound(P + 1, P + n * 4 + 1, tp) - P;
    tp = { ex + 1, -INF * 2 - 1, -1 };
    int e = lower_bound(P + 1, P + n * 4 + 1, tp) - P - 1;
    Do(a, b - 1, e - 1);
}
int main() {
    int i, j;
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
        scanf("%d%d%d", &w[i].x, &w[i].y, &w[i].r);
        w[i].num = i;
    }
    sort(w + 1, w + n + 1);
    for (i = 1; i <= n; i++) {
        P[i] = { w[i].x - w[i].r,w[i].y - w[i].r,i };
        P[i+n] = { w[i].x - w[i].r,w[i].y + w[i].r,i };
        P[i+n+n] = { w[i].x + w[i].r,w[i].y - w[i].r,i };
        P[i+n+n+n] = { w[i].x + w[i].r,w[i].y + w[i].r,i };
    }
    sort(P + 1, P + n*4 + 1);
    for (i = 0; i < n * 4; i++) {
        U[0][i] = i + 1;
    }
    for (i = 0; i < 20; i++) {
        for (j = 0; j < n * 4; j += (1 << (i + 1))) {
            int mid = j + (1 << i), ed = j + (1 << (i + 1));
            int p1 = j, p2 = mid, pv = j;
            while (p1 < mid || p2 < ed) {
                if (p2 == ed || (p1 != mid && P[U[i][p1]].y < P[U[i][p2]].y)) {
                    U[i + 1][pv++] = U[i][p1++];
                }
                else {
                    U[i + 1][pv++] = U[i][p2++];
                }
            }
        }
    }
    for (i = 0; i <= n * 4 + 10; i++) {
        for (j = 0; j <= 20; j++)UF[i][j] = i;
    }
    for (i = 1; i <= n; i++) {
        if (Res[w[i].num])continue;
        Res[w[i].num] = w[i].num;
        Go(i, w[i].x - w[i].r, w[i].x + w[i].r, w[i].y - w[i].r, w[i].y + w[i].r);
    }
    for (i = 1; i <= n; i++)printf("%d ", Res[i]);
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:88:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
circle_selection.cpp:90:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &w[i].x, &w[i].y, &w[i].r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8696 KB Output is correct
2 Correct 13 ms 8808 KB Output is correct
3 Correct 12 ms 8808 KB Output is correct
4 Correct 12 ms 8808 KB Output is correct
5 Correct 12 ms 8808 KB Output is correct
6 Correct 13 ms 8868 KB Output is correct
7 Correct 12 ms 8868 KB Output is correct
8 Correct 12 ms 8868 KB Output is correct
9 Correct 13 ms 8868 KB Output is correct
10 Correct 12 ms 8868 KB Output is correct
11 Correct 12 ms 8908 KB Output is correct
12 Correct 12 ms 8956 KB Output is correct
13 Correct 13 ms 9088 KB Output is correct
14 Correct 13 ms 9088 KB Output is correct
15 Correct 12 ms 9088 KB Output is correct
16 Correct 14 ms 9432 KB Output is correct
17 Correct 13 ms 9532 KB Output is correct
18 Correct 14 ms 9548 KB Output is correct
19 Correct 24 ms 12108 KB Output is correct
20 Correct 21 ms 12108 KB Output is correct
21 Correct 22 ms 12124 KB Output is correct
22 Correct 24 ms 12140 KB Output is correct
23 Correct 28 ms 12140 KB Output is correct
24 Correct 26 ms 12156 KB Output is correct
25 Correct 23 ms 12156 KB Output is correct
26 Correct 25 ms 12192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 938 ms 230984 KB Output is correct
2 Correct 977 ms 231056 KB Output is correct
3 Correct 991 ms 231056 KB Output is correct
4 Correct 1018 ms 231144 KB Output is correct
5 Correct 904 ms 231144 KB Output is correct
6 Correct 1016 ms 231144 KB Output is correct
7 Correct 974 ms 231144 KB Output is correct
8 Correct 1008 ms 231144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 231144 KB Output is correct
2 Correct 550 ms 231144 KB Output is correct
3 Correct 1758 ms 231144 KB Output is correct
4 Correct 1761 ms 231144 KB Output is correct
5 Correct 1668 ms 231144 KB Output is correct
6 Correct 751 ms 231144 KB Output is correct
7 Correct 354 ms 231144 KB Output is correct
8 Correct 77 ms 231144 KB Output is correct
9 Correct 1719 ms 231144 KB Output is correct
10 Correct 1612 ms 231144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1468 ms 231144 KB Output is correct
2 Correct 1273 ms 231144 KB Output is correct
3 Correct 1032 ms 231144 KB Output is correct
4 Correct 1207 ms 231144 KB Output is correct
5 Correct 1211 ms 231144 KB Output is correct
6 Correct 929 ms 231144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8696 KB Output is correct
2 Correct 13 ms 8808 KB Output is correct
3 Correct 12 ms 8808 KB Output is correct
4 Correct 12 ms 8808 KB Output is correct
5 Correct 12 ms 8808 KB Output is correct
6 Correct 13 ms 8868 KB Output is correct
7 Correct 12 ms 8868 KB Output is correct
8 Correct 12 ms 8868 KB Output is correct
9 Correct 13 ms 8868 KB Output is correct
10 Correct 12 ms 8868 KB Output is correct
11 Correct 12 ms 8908 KB Output is correct
12 Correct 12 ms 8956 KB Output is correct
13 Correct 13 ms 9088 KB Output is correct
14 Correct 13 ms 9088 KB Output is correct
15 Correct 12 ms 9088 KB Output is correct
16 Correct 14 ms 9432 KB Output is correct
17 Correct 13 ms 9532 KB Output is correct
18 Correct 14 ms 9548 KB Output is correct
19 Correct 24 ms 12108 KB Output is correct
20 Correct 21 ms 12108 KB Output is correct
21 Correct 22 ms 12124 KB Output is correct
22 Correct 24 ms 12140 KB Output is correct
23 Correct 28 ms 12140 KB Output is correct
24 Correct 26 ms 12156 KB Output is correct
25 Correct 23 ms 12156 KB Output is correct
26 Correct 25 ms 12192 KB Output is correct
27 Correct 33 ms 231144 KB Output is correct
28 Correct 35 ms 231144 KB Output is correct
29 Correct 39 ms 231144 KB Output is correct
30 Correct 44 ms 231144 KB Output is correct
31 Correct 39 ms 231144 KB Output is correct
32 Correct 36 ms 231144 KB Output is correct
33 Correct 342 ms 231144 KB Output is correct
34 Correct 294 ms 231144 KB Output is correct
35 Correct 315 ms 231144 KB Output is correct
36 Correct 420 ms 231144 KB Output is correct
37 Correct 403 ms 231144 KB Output is correct
38 Correct 437 ms 231144 KB Output is correct
39 Correct 465 ms 231144 KB Output is correct
40 Correct 416 ms 231144 KB Output is correct
41 Correct 398 ms 231144 KB Output is correct
42 Correct 348 ms 231144 KB Output is correct
43 Correct 346 ms 231144 KB Output is correct
44 Correct 379 ms 231144 KB Output is correct
45 Correct 312 ms 231144 KB Output is correct
46 Correct 308 ms 231144 KB Output is correct
47 Correct 279 ms 231144 KB Output is correct
48 Correct 306 ms 231144 KB Output is correct
49 Correct 327 ms 231144 KB Output is correct
50 Correct 314 ms 231144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8696 KB Output is correct
2 Correct 13 ms 8808 KB Output is correct
3 Correct 12 ms 8808 KB Output is correct
4 Correct 12 ms 8808 KB Output is correct
5 Correct 12 ms 8808 KB Output is correct
6 Correct 13 ms 8868 KB Output is correct
7 Correct 12 ms 8868 KB Output is correct
8 Correct 12 ms 8868 KB Output is correct
9 Correct 13 ms 8868 KB Output is correct
10 Correct 12 ms 8868 KB Output is correct
11 Correct 12 ms 8908 KB Output is correct
12 Correct 12 ms 8956 KB Output is correct
13 Correct 13 ms 9088 KB Output is correct
14 Correct 13 ms 9088 KB Output is correct
15 Correct 12 ms 9088 KB Output is correct
16 Correct 14 ms 9432 KB Output is correct
17 Correct 13 ms 9532 KB Output is correct
18 Correct 14 ms 9548 KB Output is correct
19 Correct 24 ms 12108 KB Output is correct
20 Correct 21 ms 12108 KB Output is correct
21 Correct 22 ms 12124 KB Output is correct
22 Correct 24 ms 12140 KB Output is correct
23 Correct 28 ms 12140 KB Output is correct
24 Correct 26 ms 12156 KB Output is correct
25 Correct 23 ms 12156 KB Output is correct
26 Correct 25 ms 12192 KB Output is correct
27 Correct 938 ms 230984 KB Output is correct
28 Correct 977 ms 231056 KB Output is correct
29 Correct 991 ms 231056 KB Output is correct
30 Correct 1018 ms 231144 KB Output is correct
31 Correct 904 ms 231144 KB Output is correct
32 Correct 1016 ms 231144 KB Output is correct
33 Correct 974 ms 231144 KB Output is correct
34 Correct 1008 ms 231144 KB Output is correct
35 Correct 13 ms 231144 KB Output is correct
36 Correct 550 ms 231144 KB Output is correct
37 Correct 1758 ms 231144 KB Output is correct
38 Correct 1761 ms 231144 KB Output is correct
39 Correct 1668 ms 231144 KB Output is correct
40 Correct 751 ms 231144 KB Output is correct
41 Correct 354 ms 231144 KB Output is correct
42 Correct 77 ms 231144 KB Output is correct
43 Correct 1719 ms 231144 KB Output is correct
44 Correct 1612 ms 231144 KB Output is correct
45 Correct 1468 ms 231144 KB Output is correct
46 Correct 1273 ms 231144 KB Output is correct
47 Correct 1032 ms 231144 KB Output is correct
48 Correct 1207 ms 231144 KB Output is correct
49 Correct 1211 ms 231144 KB Output is correct
50 Correct 929 ms 231144 KB Output is correct
51 Correct 33 ms 231144 KB Output is correct
52 Correct 35 ms 231144 KB Output is correct
53 Correct 39 ms 231144 KB Output is correct
54 Correct 44 ms 231144 KB Output is correct
55 Correct 39 ms 231144 KB Output is correct
56 Correct 36 ms 231144 KB Output is correct
57 Correct 342 ms 231144 KB Output is correct
58 Correct 294 ms 231144 KB Output is correct
59 Correct 315 ms 231144 KB Output is correct
60 Correct 420 ms 231144 KB Output is correct
61 Correct 403 ms 231144 KB Output is correct
62 Correct 437 ms 231144 KB Output is correct
63 Correct 465 ms 231144 KB Output is correct
64 Correct 416 ms 231144 KB Output is correct
65 Correct 398 ms 231144 KB Output is correct
66 Correct 348 ms 231144 KB Output is correct
67 Correct 346 ms 231144 KB Output is correct
68 Correct 379 ms 231144 KB Output is correct
69 Correct 312 ms 231144 KB Output is correct
70 Correct 308 ms 231144 KB Output is correct
71 Correct 279 ms 231144 KB Output is correct
72 Correct 306 ms 231144 KB Output is correct
73 Correct 327 ms 231144 KB Output is correct
74 Correct 314 ms 231144 KB Output is correct
75 Correct 1094 ms 231144 KB Output is correct
76 Correct 1050 ms 231144 KB Output is correct
77 Correct 1036 ms 231144 KB Output is correct
78 Correct 977 ms 231144 KB Output is correct
79 Correct 1061 ms 231144 KB Output is correct
80 Correct 1081 ms 231144 KB Output is correct
81 Correct 1358 ms 231144 KB Output is correct
82 Correct 1353 ms 231144 KB Output is correct
83 Correct 1497 ms 231144 KB Output is correct
84 Correct 1595 ms 231144 KB Output is correct
85 Correct 1514 ms 231144 KB Output is correct
86 Correct 1449 ms 231144 KB Output is correct
87 Correct 2281 ms 231144 KB Output is correct
88 Correct 1406 ms 231144 KB Output is correct
89 Correct 1276 ms 231144 KB Output is correct
90 Correct 1474 ms 231144 KB Output is correct
91 Correct 1368 ms 231144 KB Output is correct
92 Correct 1421 ms 231144 KB Output is correct
93 Correct 1372 ms 231144 KB Output is correct
94 Correct 3399 ms 231144 KB Output is correct
95 Correct 1396 ms 231144 KB Output is correct
96 Correct 1313 ms 231144 KB Output is correct
97 Correct 3120 ms 231144 KB Output is correct
98 Correct 1068 ms 231144 KB Output is correct
99 Correct 1269 ms 231144 KB Output is correct
100 Correct 1230 ms 231144 KB Output is correct
101 Correct 1161 ms 231144 KB Output is correct
102 Correct 1279 ms 231144 KB Output is correct
103 Correct 3570 ms 231144 KB Output is correct
104 Correct 1292 ms 231144 KB Output is correct
105 Correct 1211 ms 231144 KB Output is correct
106 Correct 1000 ms 231144 KB Output is correct
107 Correct 988 ms 231144 KB Output is correct
108 Correct 907 ms 231144 KB Output is correct
109 Correct 1020 ms 231144 KB Output is correct
110 Correct 1134 ms 231144 KB Output is correct
111 Correct 1016 ms 231144 KB Output is correct
112 Correct 1087 ms 231144 KB Output is correct
113 Correct 1042 ms 231144 KB Output is correct
114 Correct 1061 ms 231144 KB Output is correct
115 Correct 1476 ms 231144 KB Output is correct
116 Correct 1080 ms 231144 KB Output is correct