답안 #405648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405648 2021-05-16T16:08:55 Z rqi 원 고르기 (APIO18_circle_selection) C++14
100 / 100
1947 ms 383952 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;
typedef double db;

#define f first
#define s second
#define pb push_back
#define mp make_pair

#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)

mt19937 rng(127);
const int SZ = 100;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;


const uint64_t C = ll(2e18*3.1415926535)+71; // large odd number
const int RANDOM = rng(); // random 32-bit number
ll hashNum(ll x) {
    // https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
    return __builtin_bswap64((x^RANDOM)*C);
}

struct hashFunc{
    ll operator()(const pl& a) const {
        return hashNum(a.f)^(hashNum(a.s)+1);
    }
};

const int mx = 300005;
int n;
ll x[mx];
ll y[mx];
ll r[mx];

bool circIntersect(int a, int b){
    ll dist_sq = (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]);
    if(dist_sq <= (r[a]+r[b])*(r[a]+r[b])){
        return true;
    }
    return false;
}

vector<pair<ll, int>> buckets[35];
int ans[mx];
gp_hash_table<pl, vi, hashFunc> g;
ll GRID;

ll fdiv(ll a, ll b){
    assert(b >= 1);
    if(a >= 0) return a/b;
    return (a+1)/b-1;
}

pl gridReduce(pl a){
    return mp(fdiv(a.f, GRID), fdiv(a.s, GRID));
}

void remDup(vpl& a){
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

vpl getCorners(int circ){
    vpl corners = vpl{mp(x[circ]+r[circ], y[circ]+r[circ]), mp(x[circ]-r[circ], y[circ]+r[circ]), mp(x[circ]-r[circ], y[circ]-r[circ]), mp(x[circ]+r[circ], y[circ]-r[circ])};
    vector<pl> res;
    for(auto u: corners){
        res.pb(gridReduce(u));
    }
    remDup(res);
    return res;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    // n = 300000;
    // clock_t c = clock();
    // cout << fixed << setprecision(6);
    
    for(int i = 1; i <= n; i++){
        cin >> x[i] >> y[i] >> r[i];
        // x[i] = rng() % SZ - SZ/2;
        // y[i] = rng() % SZ - SZ/2;
        // r[i] = 1 + rng() % SZ;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 35; j++){
            if(r[i] < (1LL<<j)){
                buckets[j-1].pb(mp(-r[i], i));
                break;
            }
        }
    }
    assert(sz(buckets[30]) == 0);
    //cout << db(clock()-c)/db(CLOCKS_PER_SEC) << "\n";

    int num = 0;
    for(int k = 29; k >= 0; k--){
        sort(all(buckets[k]));
        if(sz(buckets[k]) == 0) continue;
        g.clear();
        GRID = (1LL<<(k+2));
        for(int i = 1; i <= n; i++){
            if(ans[i] == 0){
                for(auto u: getCorners(i)){
                    g[u].pb(i);
                    num++;
                }
            }
        }

        for(auto circ: buckets[k]){
            int ind = circ.s;
            if(ans[ind] == 0){
                for(auto u: getCorners(ind)){
                    vi new_cands;
                    for(auto cand: g[u]){
                        //num++;
                        if(ans[cand] != 0) continue;
                        if(circIntersect(ind, cand)){
                            ans[cand] = ind;
                        }
                        else{
                            new_cands.pb(cand);
                        }
                    }
                    g[u] = new_cands;
                }
                assert(ans[ind] == ind);
            }
        }
    }
    // cout << num << "\n";
    //  cout << db(clock()-c)/db(CLOCKS_PER_SEC) << "\n";
    for(int i = 1; i <= n; i++){
        cout << ans[i] << " ";
    }
    cout << "\n";
    // cout << db(clock()-c)/db(CLOCKS_PER_SEC) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 7 ms 836 KB Output is correct
20 Correct 6 ms 860 KB Output is correct
21 Correct 5 ms 800 KB Output is correct
22 Correct 15 ms 3444 KB Output is correct
23 Correct 19 ms 3588 KB Output is correct
24 Correct 16 ms 3440 KB Output is correct
25 Correct 16 ms 3456 KB Output is correct
26 Correct 18 ms 3572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 288 ms 23172 KB Output is correct
2 Correct 270 ms 21412 KB Output is correct
3 Correct 288 ms 20508 KB Output is correct
4 Correct 261 ms 22128 KB Output is correct
5 Correct 294 ms 23976 KB Output is correct
6 Correct 744 ms 43848 KB Output is correct
7 Correct 330 ms 26320 KB Output is correct
8 Correct 437 ms 30848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 483 ms 55320 KB Output is correct
3 Correct 1607 ms 202100 KB Output is correct
4 Correct 1550 ms 201680 KB Output is correct
5 Correct 1510 ms 122328 KB Output is correct
6 Correct 603 ms 58676 KB Output is correct
7 Correct 262 ms 30196 KB Output is correct
8 Correct 35 ms 7112 KB Output is correct
9 Correct 1914 ms 214392 KB Output is correct
10 Correct 1423 ms 123720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1119 ms 199264 KB Output is correct
2 Correct 1107 ms 202888 KB Output is correct
3 Correct 423 ms 31680 KB Output is correct
4 Correct 1151 ms 203192 KB Output is correct
5 Correct 1622 ms 383952 KB Output is correct
6 Correct 318 ms 29220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 7 ms 836 KB Output is correct
20 Correct 6 ms 860 KB Output is correct
21 Correct 5 ms 800 KB Output is correct
22 Correct 15 ms 3444 KB Output is correct
23 Correct 19 ms 3588 KB Output is correct
24 Correct 16 ms 3440 KB Output is correct
25 Correct 16 ms 3456 KB Output is correct
26 Correct 18 ms 3572 KB Output is correct
27 Correct 10 ms 1356 KB Output is correct
28 Correct 9 ms 1240 KB Output is correct
29 Correct 9 ms 1272 KB Output is correct
30 Correct 31 ms 6696 KB Output is correct
31 Correct 36 ms 6868 KB Output is correct
32 Correct 32 ms 6688 KB Output is correct
33 Correct 87 ms 9200 KB Output is correct
34 Correct 89 ms 9812 KB Output is correct
35 Correct 88 ms 9368 KB Output is correct
36 Correct 485 ms 52952 KB Output is correct
37 Correct 474 ms 55104 KB Output is correct
38 Correct 477 ms 53104 KB Output is correct
39 Correct 595 ms 12712 KB Output is correct
40 Correct 612 ms 12680 KB Output is correct
41 Correct 597 ms 12588 KB Output is correct
42 Correct 138 ms 11396 KB Output is correct
43 Correct 484 ms 98144 KB Output is correct
44 Correct 466 ms 97032 KB Output is correct
45 Correct 478 ms 97136 KB Output is correct
46 Correct 505 ms 97064 KB Output is correct
47 Correct 473 ms 97076 KB Output is correct
48 Correct 451 ms 98044 KB Output is correct
49 Correct 494 ms 97148 KB Output is correct
50 Correct 458 ms 97120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 7 ms 836 KB Output is correct
20 Correct 6 ms 860 KB Output is correct
21 Correct 5 ms 800 KB Output is correct
22 Correct 15 ms 3444 KB Output is correct
23 Correct 19 ms 3588 KB Output is correct
24 Correct 16 ms 3440 KB Output is correct
25 Correct 16 ms 3456 KB Output is correct
26 Correct 18 ms 3572 KB Output is correct
27 Correct 288 ms 23172 KB Output is correct
28 Correct 270 ms 21412 KB Output is correct
29 Correct 288 ms 20508 KB Output is correct
30 Correct 261 ms 22128 KB Output is correct
31 Correct 294 ms 23976 KB Output is correct
32 Correct 744 ms 43848 KB Output is correct
33 Correct 330 ms 26320 KB Output is correct
34 Correct 437 ms 30848 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 483 ms 55320 KB Output is correct
37 Correct 1607 ms 202100 KB Output is correct
38 Correct 1550 ms 201680 KB Output is correct
39 Correct 1510 ms 122328 KB Output is correct
40 Correct 603 ms 58676 KB Output is correct
41 Correct 262 ms 30196 KB Output is correct
42 Correct 35 ms 7112 KB Output is correct
43 Correct 1914 ms 214392 KB Output is correct
44 Correct 1423 ms 123720 KB Output is correct
45 Correct 1119 ms 199264 KB Output is correct
46 Correct 1107 ms 202888 KB Output is correct
47 Correct 423 ms 31680 KB Output is correct
48 Correct 1151 ms 203192 KB Output is correct
49 Correct 1622 ms 383952 KB Output is correct
50 Correct 318 ms 29220 KB Output is correct
51 Correct 10 ms 1356 KB Output is correct
52 Correct 9 ms 1240 KB Output is correct
53 Correct 9 ms 1272 KB Output is correct
54 Correct 31 ms 6696 KB Output is correct
55 Correct 36 ms 6868 KB Output is correct
56 Correct 32 ms 6688 KB Output is correct
57 Correct 87 ms 9200 KB Output is correct
58 Correct 89 ms 9812 KB Output is correct
59 Correct 88 ms 9368 KB Output is correct
60 Correct 485 ms 52952 KB Output is correct
61 Correct 474 ms 55104 KB Output is correct
62 Correct 477 ms 53104 KB Output is correct
63 Correct 595 ms 12712 KB Output is correct
64 Correct 612 ms 12680 KB Output is correct
65 Correct 597 ms 12588 KB Output is correct
66 Correct 138 ms 11396 KB Output is correct
67 Correct 484 ms 98144 KB Output is correct
68 Correct 466 ms 97032 KB Output is correct
69 Correct 478 ms 97136 KB Output is correct
70 Correct 505 ms 97064 KB Output is correct
71 Correct 473 ms 97076 KB Output is correct
72 Correct 451 ms 98044 KB Output is correct
73 Correct 494 ms 97148 KB Output is correct
74 Correct 458 ms 97120 KB Output is correct
75 Correct 276 ms 26340 KB Output is correct
76 Correct 273 ms 25292 KB Output is correct
77 Correct 275 ms 27372 KB Output is correct
78 Correct 273 ms 26760 KB Output is correct
79 Correct 297 ms 27608 KB Output is correct
80 Correct 314 ms 27816 KB Output is correct
81 Correct 1947 ms 222968 KB Output is correct
82 Correct 1597 ms 202108 KB Output is correct
83 Correct 1594 ms 201612 KB Output is correct
84 Correct 1642 ms 202320 KB Output is correct
85 Correct 1585 ms 201796 KB Output is correct
86 Correct 1644 ms 202020 KB Output is correct
87 Correct 1586 ms 201912 KB Output is correct
88 Correct 1749 ms 34044 KB Output is correct
89 Correct 1745 ms 33980 KB Output is correct
90 Correct 1722 ms 34084 KB Output is correct
91 Correct 1723 ms 33852 KB Output is correct
92 Correct 1748 ms 34084 KB Output is correct
93 Correct 1437 ms 200696 KB Output is correct
94 Correct 1483 ms 201572 KB Output is correct
95 Correct 1626 ms 208980 KB Output is correct
96 Correct 1697 ms 213412 KB Output is correct
97 Correct 1387 ms 200740 KB Output is correct
98 Correct 695 ms 45504 KB Output is correct
99 Correct 1624 ms 201060 KB Output is correct
100 Correct 1246 ms 114392 KB Output is correct
101 Correct 902 ms 68956 KB Output is correct
102 Correct 1492 ms 200856 KB Output is correct
103 Correct 1745 ms 221876 KB Output is correct
104 Correct 1493 ms 200692 KB Output is correct
105 Correct 500 ms 35916 KB Output is correct
106 Correct 1339 ms 203724 KB Output is correct
107 Correct 1344 ms 203468 KB Output is correct
108 Correct 1327 ms 203696 KB Output is correct
109 Correct 1312 ms 203488 KB Output is correct
110 Correct 1324 ms 203740 KB Output is correct
111 Correct 1340 ms 203496 KB Output is correct
112 Correct 1385 ms 203556 KB Output is correct
113 Correct 1349 ms 203580 KB Output is correct
114 Correct 1336 ms 203488 KB Output is correct
115 Correct 1337 ms 203584 KB Output is correct
116 Correct 1341 ms 203556 KB Output is correct