답안 #391064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391064 2021-04-17T17:59:47 Z phathnv 원 고르기 (APIO18_circle_selection) C++11
100 / 100
1510 ms 47544 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 3e5 + 7;

struct Circle{
    int x, y, r;
};

int n, answer[N], ord[N], ordX[N], numRow, inRow[N];
vector<int> row[N];
Circle c[N];

bool Intersect(const Circle &c1, const Circle &c2){
    int dx = c1.x - c2.x;
    int dy = c1.y - c2.y;
    int sr = c1.r + c2.r;
    return (ll) dx * dx + (ll) dy * dy <= (ll) sr * sr;
}

void Rebuild(int k){
    for(int i = 1; i <= numRow; i++)
        row[i].clear();

    numRow = 0;
    int last = -1;
    for(int i = 1; i <= n; i++){
        int ind = ordX[i];
        if (answer[ind])
            continue;
        if ((c[ind].x >> k) != last){
            last = c[ind].x >> k;
            numRow++;
        }
        row[numRow].push_back(ind);
        inRow[ind] = numRow;
    }
    for(int i = 1; i <= numRow; i++)
        sort(row[i].begin(), row[i].end(), [&](const int &a, const int &b){
                return (c[a].y >> k) < (c[b].y >> k);
             });
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> c[i].x >> c[i].y >> c[i].r;
        c[i].x += 1e9;
        c[i].y += 1e9;
        ord[i] = i;
        ordX[i] = i;
    }

    sort(ord + 1, ord + 1 + n, [&](const int &a, const int &b){
            if (c[a].r != c[b].r)
                return c[a].r > c[b].r;
            return a < b;
         });
    sort(ordX + 1, ordX + 1 + n, [&](const int &a, const int &b){
            return c[a].x < c[b].x;
         });
    int k = 30;
    Rebuild(k);
    for(int i = 1; i <= n; i++){
        int ind = ord[i];
        if (answer[ind])
            continue;
        while (k && c[ind].r <= (1 << (k - 1)))
            Rebuild(--k);
        for(int x = max(1, inRow[ind] - 2); x <= min(numRow, inRow[ind] + 2); x++){
            if (abs((c[row[x][0]].x >> k) - (c[ind].x >> k)) > 2)
                continue;
            int l = 0, r = row[x].size() - 1, p = row[x].size();
            while (l <= r){
                int mid = (l + r) >> 1;
                if ((c[row[x][mid]].y >> k) >= (c[ind].y >> k) - 2){
                    p = mid;
                    r = mid - 1;
                } else {
                    l = mid + 1;
                }
            }

            while (p < (int) row[x].size()){
                if (Intersect(c[ind], c[row[x][p]]) && !answer[row[x][p]])
                    answer[row[x][p]] = ind;
                if ((c[row[x][p]].y >> k) > (c[ind].y >> k) + 2)
                    break;
                p++;
            }
         }
    }

    for(int i = 1; i <= n; i++)
        cout << answer[i] << ' ';

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 5 ms 7500 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7376 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 6 ms 7372 KB Output is correct
9 Correct 5 ms 7348 KB Output is correct
10 Correct 5 ms 7372 KB Output is correct
11 Correct 5 ms 7372 KB Output is correct
12 Correct 5 ms 7308 KB Output is correct
13 Correct 5 ms 7372 KB Output is correct
14 Correct 5 ms 7372 KB Output is correct
15 Correct 5 ms 7372 KB Output is correct
16 Correct 6 ms 7372 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 5 ms 7372 KB Output is correct
19 Correct 8 ms 7532 KB Output is correct
20 Correct 8 ms 7500 KB Output is correct
21 Correct 8 ms 7500 KB Output is correct
22 Correct 13 ms 7756 KB Output is correct
23 Correct 15 ms 7628 KB Output is correct
24 Correct 13 ms 7824 KB Output is correct
25 Correct 12 ms 7848 KB Output is correct
26 Correct 12 ms 7828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 257 ms 19260 KB Output is correct
2 Correct 274 ms 19736 KB Output is correct
3 Correct 291 ms 20068 KB Output is correct
4 Correct 240 ms 18992 KB Output is correct
5 Correct 604 ms 27576 KB Output is correct
6 Correct 662 ms 39568 KB Output is correct
7 Correct 562 ms 33080 KB Output is correct
8 Correct 726 ms 37196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 190 ms 14148 KB Output is correct
3 Correct 878 ms 38996 KB Output is correct
4 Correct 833 ms 38984 KB Output is correct
5 Correct 690 ms 36280 KB Output is correct
6 Correct 296 ms 22600 KB Output is correct
7 Correct 152 ms 15420 KB Output is correct
8 Correct 30 ms 9184 KB Output is correct
9 Correct 776 ms 39484 KB Output is correct
10 Correct 676 ms 35264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 812 ms 30596 KB Output is correct
2 Correct 1008 ms 45692 KB Output is correct
3 Correct 488 ms 31204 KB Output is correct
4 Correct 838 ms 44184 KB Output is correct
5 Correct 818 ms 47300 KB Output is correct
6 Correct 448 ms 30580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 5 ms 7500 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7376 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 6 ms 7372 KB Output is correct
9 Correct 5 ms 7348 KB Output is correct
10 Correct 5 ms 7372 KB Output is correct
11 Correct 5 ms 7372 KB Output is correct
12 Correct 5 ms 7308 KB Output is correct
13 Correct 5 ms 7372 KB Output is correct
14 Correct 5 ms 7372 KB Output is correct
15 Correct 5 ms 7372 KB Output is correct
16 Correct 6 ms 7372 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 5 ms 7372 KB Output is correct
19 Correct 8 ms 7532 KB Output is correct
20 Correct 8 ms 7500 KB Output is correct
21 Correct 8 ms 7500 KB Output is correct
22 Correct 13 ms 7756 KB Output is correct
23 Correct 15 ms 7628 KB Output is correct
24 Correct 13 ms 7824 KB Output is correct
25 Correct 12 ms 7848 KB Output is correct
26 Correct 12 ms 7828 KB Output is correct
27 Correct 14 ms 7756 KB Output is correct
28 Correct 12 ms 7756 KB Output is correct
29 Correct 14 ms 7704 KB Output is correct
30 Correct 23 ms 7980 KB Output is correct
31 Correct 20 ms 8236 KB Output is correct
32 Correct 22 ms 8140 KB Output is correct
33 Correct 79 ms 11128 KB Output is correct
34 Correct 82 ms 11240 KB Output is correct
35 Correct 96 ms 11604 KB Output is correct
36 Correct 212 ms 15900 KB Output is correct
37 Correct 219 ms 18420 KB Output is correct
38 Correct 203 ms 17876 KB Output is correct
39 Correct 296 ms 14932 KB Output is correct
40 Correct 298 ms 14924 KB Output is correct
41 Correct 286 ms 14912 KB Output is correct
42 Correct 194 ms 14680 KB Output is correct
43 Correct 156 ms 20340 KB Output is correct
44 Correct 167 ms 20312 KB Output is correct
45 Correct 162 ms 20380 KB Output is correct
46 Correct 161 ms 20280 KB Output is correct
47 Correct 151 ms 20292 KB Output is correct
48 Correct 154 ms 20300 KB Output is correct
49 Correct 150 ms 20296 KB Output is correct
50 Correct 151 ms 20320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 5 ms 7500 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7376 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 6 ms 7372 KB Output is correct
9 Correct 5 ms 7348 KB Output is correct
10 Correct 5 ms 7372 KB Output is correct
11 Correct 5 ms 7372 KB Output is correct
12 Correct 5 ms 7308 KB Output is correct
13 Correct 5 ms 7372 KB Output is correct
14 Correct 5 ms 7372 KB Output is correct
15 Correct 5 ms 7372 KB Output is correct
16 Correct 6 ms 7372 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 5 ms 7372 KB Output is correct
19 Correct 8 ms 7532 KB Output is correct
20 Correct 8 ms 7500 KB Output is correct
21 Correct 8 ms 7500 KB Output is correct
22 Correct 13 ms 7756 KB Output is correct
23 Correct 15 ms 7628 KB Output is correct
24 Correct 13 ms 7824 KB Output is correct
25 Correct 12 ms 7848 KB Output is correct
26 Correct 12 ms 7828 KB Output is correct
27 Correct 257 ms 19260 KB Output is correct
28 Correct 274 ms 19736 KB Output is correct
29 Correct 291 ms 20068 KB Output is correct
30 Correct 240 ms 18992 KB Output is correct
31 Correct 604 ms 27576 KB Output is correct
32 Correct 662 ms 39568 KB Output is correct
33 Correct 562 ms 33080 KB Output is correct
34 Correct 726 ms 37196 KB Output is correct
35 Correct 4 ms 7372 KB Output is correct
36 Correct 190 ms 14148 KB Output is correct
37 Correct 878 ms 38996 KB Output is correct
38 Correct 833 ms 38984 KB Output is correct
39 Correct 690 ms 36280 KB Output is correct
40 Correct 296 ms 22600 KB Output is correct
41 Correct 152 ms 15420 KB Output is correct
42 Correct 30 ms 9184 KB Output is correct
43 Correct 776 ms 39484 KB Output is correct
44 Correct 676 ms 35264 KB Output is correct
45 Correct 812 ms 30596 KB Output is correct
46 Correct 1008 ms 45692 KB Output is correct
47 Correct 488 ms 31204 KB Output is correct
48 Correct 838 ms 44184 KB Output is correct
49 Correct 818 ms 47300 KB Output is correct
50 Correct 448 ms 30580 KB Output is correct
51 Correct 14 ms 7756 KB Output is correct
52 Correct 12 ms 7756 KB Output is correct
53 Correct 14 ms 7704 KB Output is correct
54 Correct 23 ms 7980 KB Output is correct
55 Correct 20 ms 8236 KB Output is correct
56 Correct 22 ms 8140 KB Output is correct
57 Correct 79 ms 11128 KB Output is correct
58 Correct 82 ms 11240 KB Output is correct
59 Correct 96 ms 11604 KB Output is correct
60 Correct 212 ms 15900 KB Output is correct
61 Correct 219 ms 18420 KB Output is correct
62 Correct 203 ms 17876 KB Output is correct
63 Correct 296 ms 14932 KB Output is correct
64 Correct 298 ms 14924 KB Output is correct
65 Correct 286 ms 14912 KB Output is correct
66 Correct 194 ms 14680 KB Output is correct
67 Correct 156 ms 20340 KB Output is correct
68 Correct 167 ms 20312 KB Output is correct
69 Correct 162 ms 20380 KB Output is correct
70 Correct 161 ms 20280 KB Output is correct
71 Correct 151 ms 20292 KB Output is correct
72 Correct 154 ms 20300 KB Output is correct
73 Correct 150 ms 20296 KB Output is correct
74 Correct 151 ms 20320 KB Output is correct
75 Correct 313 ms 28820 KB Output is correct
76 Correct 307 ms 28892 KB Output is correct
77 Correct 299 ms 28212 KB Output is correct
78 Correct 250 ms 27616 KB Output is correct
79 Correct 370 ms 28792 KB Output is correct
80 Correct 253 ms 27700 KB Output is correct
81 Correct 798 ms 40092 KB Output is correct
82 Correct 746 ms 38580 KB Output is correct
83 Correct 766 ms 40900 KB Output is correct
84 Correct 770 ms 40240 KB Output is correct
85 Correct 806 ms 39364 KB Output is correct
86 Correct 738 ms 39476 KB Output is correct
87 Correct 895 ms 35324 KB Output is correct
88 Correct 1028 ms 31364 KB Output is correct
89 Correct 1045 ms 31376 KB Output is correct
90 Correct 1077 ms 31348 KB Output is correct
91 Correct 1120 ms 31276 KB Output is correct
92 Correct 1217 ms 31364 KB Output is correct
93 Correct 747 ms 47544 KB Output is correct
94 Correct 1319 ms 26944 KB Output is correct
95 Correct 711 ms 47268 KB Output is correct
96 Correct 754 ms 46764 KB Output is correct
97 Correct 1510 ms 30368 KB Output is correct
98 Correct 633 ms 40328 KB Output is correct
99 Correct 746 ms 46376 KB Output is correct
100 Correct 701 ms 44732 KB Output is correct
101 Correct 695 ms 38620 KB Output is correct
102 Correct 754 ms 45316 KB Output is correct
103 Correct 1396 ms 28412 KB Output is correct
104 Correct 738 ms 44928 KB Output is correct
105 Correct 707 ms 30268 KB Output is correct
106 Correct 627 ms 46056 KB Output is correct
107 Correct 654 ms 46008 KB Output is correct
108 Correct 668 ms 45924 KB Output is correct
109 Correct 612 ms 46076 KB Output is correct
110 Correct 629 ms 46060 KB Output is correct
111 Correct 646 ms 46084 KB Output is correct
112 Correct 683 ms 45912 KB Output is correct
113 Correct 622 ms 46148 KB Output is correct
114 Correct 775 ms 45964 KB Output is correct
115 Correct 691 ms 46040 KB Output is correct
116 Correct 764 ms 46268 KB Output is correct