Submission #970419

# Submission time Handle Problem Language Result Execution time Memory
970419 2024-04-26T13:46:42 Z steveonalex Circle selection (APIO18_circle_selection) C++17
100 / 100
2289 ms 49296 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
 
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b){a = b; return true;}
        return false;
    }
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b){a = b; return true;}
        return false;
    }
template <class T>
    void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
        for(auto i: a) out << i << separator;
        out << finish;
    }
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 3e5 + 69;
const ll INF = 1e9;
int n; 
int ans[N];
vector<array<ll, 4>> a, c;

ll sqr(ll x){return x * x;}
ll block_sz;

pair<ll, ll> dumb_down(pair<ll, ll> a){
    return {a.first / block_sz, a.second / block_sz};
}

vector<pair<ll, ll>> grid;
vector<int> item;

void set_up(ll arg){
    block_sz = arg;


    c = a;
    for(int i = 1; i<=n; ++i) if (ans[i] == 0) {
        c[i][0] /= block_sz;
        c[i][1] /= block_sz;
    }
    sort(1 + ALL(c), [](array<ll, 4> x, array<ll, 4> y){
        if (x[0] != y[0]) return x[0] < y[0];
        return x[1] < y[1];
    });

    grid.clear(); item.clear();
    for(int i= 1; i<=n; ++i) {
        int _i = c[i][3];
        if (ans[_i] > 0) continue;
        grid.push_back({c[i][0], c[i][1]});
        item.push_back(_i);
    }
}

ll dis(pair<ll, ll> a, pair<ll, ll> b){return sqr(a.first - b.first) + sqr(a.second - b.second);}

bool check(pair<ll, ll> point, ll r, pair<ll, ll> des){
    if (des.first < 0 || des.second < 0) return false;
    for(int x = 0; x <= 1; ++x) for(int y = 0; y<=1; ++y){
        pair<ll, ll> ligma = {des.first * block_sz, des.second * block_sz};
        if (x) ligma.first += block_sz - 1;
        if (y) ligma.second += block_sz - 1;
        if ((abs(point.first - ligma.first) + abs(point.second - ligma.second)) * 2 > r * 3) continue;
        if (dis(point, ligma) <= sqr(r)) return true;
    }
    return false;
}

bool query(int i, int j){
    return sqr(a[i][0] - a[j][0]) + sqr(a[i][1] - a[j][1]) <= sqr(a[i][2] + a[j][2]);
}

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
    cin >> n;
    a.resize(n+1);
    for(int i = 1; i<=n; ++i) {
        for(int j = 0; j < 3; ++j) cin >> a[i][j];
        a[i][0] += INF; a[i][1] += INF;
        a[i][3] = i;
    }

    vector<array<ll, 4>> b = a;
    sort(1 + ALL(b), [](array<ll, 4> x, array<ll, 4> y){
        if (x[2] != y[2]) return x[2] > y[2];
        return x[3] < y[3];
    });


    set_up((b[1][2] + 1) / 2);
    for(int i = 1; i<=n; ++i) if (ans[b[i][3]] == 0){
        int _i = b[i][3];
        ans[_i] = _i;

        if (b[i][2] < block_sz)
            set_up((b[i][2] + 1) / 2);

        pair<ll, ll> cur = make_pair(b[i][0], b[i][1]);
        pair<ll, ll> magnifico = dumb_down(cur);
        const int EXTEND = 5;
        for(int x = -EXTEND; x <= EXTEND; ++x) for(int y = -EXTEND; y<=EXTEND; ++y) {
            pair<ll, ll> cu = make_pair(magnifico.first + x, magnifico.second + y);

            // bool bruh = check(cur, b[i][2] * 2, cu);
            // if (max(abs(x), abs(y)) == EXTEND && bruh) exit(1);

            if (!binary_search(ALL(grid), cu)) continue;
            int idx = lower_bound(ALL(grid), cu) - grid.begin();
            while(idx < grid.size() && grid[idx] == cu){
                int j = item[idx];
                if (ans[j] == 0 && query(_i, j)) ans[j] = _i;
                idx++;
            }
        }
    }

    for(int i = 1; i<=n; ++i) 
        cout << ans[i] << " "; 
    cout << "\n";

    return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:140:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  140 |             while(idx < grid.size() && grid[idx] == cu){
      |                   ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 2 ms 1116 KB Output is correct
21 Correct 4 ms 1116 KB Output is correct
22 Correct 23 ms 1200 KB Output is correct
23 Correct 28 ms 1196 KB Output is correct
24 Correct 22 ms 1116 KB Output is correct
25 Correct 19 ms 1116 KB Output is correct
26 Correct 21 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 40488 KB Output is correct
2 Correct 175 ms 40440 KB Output is correct
3 Correct 142 ms 40404 KB Output is correct
4 Correct 161 ms 39968 KB Output is correct
5 Correct 292 ms 40952 KB Output is correct
6 Correct 809 ms 41328 KB Output is correct
7 Correct 408 ms 40912 KB Output is correct
8 Correct 459 ms 40304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 685 ms 13240 KB Output is correct
3 Correct 2097 ms 40956 KB Output is correct
4 Correct 2173 ms 41244 KB Output is correct
5 Correct 1816 ms 39684 KB Output is correct
6 Correct 608 ms 21248 KB Output is correct
7 Correct 297 ms 11016 KB Output is correct
8 Correct 47 ms 2588 KB Output is correct
9 Correct 2091 ms 40496 KB Output is correct
10 Correct 1303 ms 40452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1702 ms 41284 KB Output is correct
2 Correct 1242 ms 41236 KB Output is correct
3 Correct 377 ms 39728 KB Output is correct
4 Correct 1320 ms 41700 KB Output is correct
5 Correct 1272 ms 41456 KB Output is correct
6 Correct 205 ms 39680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 2 ms 1116 KB Output is correct
21 Correct 4 ms 1116 KB Output is correct
22 Correct 23 ms 1200 KB Output is correct
23 Correct 28 ms 1196 KB Output is correct
24 Correct 22 ms 1116 KB Output is correct
25 Correct 19 ms 1116 KB Output is correct
26 Correct 21 ms 1116 KB Output is correct
27 Correct 8 ms 1820 KB Output is correct
28 Correct 5 ms 1816 KB Output is correct
29 Correct 5 ms 1820 KB Output is correct
30 Correct 56 ms 1820 KB Output is correct
31 Correct 55 ms 1816 KB Output is correct
32 Correct 47 ms 1816 KB Output is correct
33 Correct 46 ms 13512 KB Output is correct
34 Correct 46 ms 13312 KB Output is correct
35 Correct 141 ms 13252 KB Output is correct
36 Correct 578 ms 13124 KB Output is correct
37 Correct 580 ms 13320 KB Output is correct
38 Correct 605 ms 13380 KB Output is correct
39 Correct 504 ms 13064 KB Output is correct
40 Correct 497 ms 13108 KB Output is correct
41 Correct 506 ms 13056 KB Output is correct
42 Correct 203 ms 13064 KB Output is correct
43 Correct 375 ms 13468 KB Output is correct
44 Correct 369 ms 13244 KB Output is correct
45 Correct 378 ms 13240 KB Output is correct
46 Correct 368 ms 13312 KB Output is correct
47 Correct 371 ms 13320 KB Output is correct
48 Correct 368 ms 13252 KB Output is correct
49 Correct 373 ms 13316 KB Output is correct
50 Correct 373 ms 13244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 2 ms 1116 KB Output is correct
21 Correct 4 ms 1116 KB Output is correct
22 Correct 23 ms 1200 KB Output is correct
23 Correct 28 ms 1196 KB Output is correct
24 Correct 22 ms 1116 KB Output is correct
25 Correct 19 ms 1116 KB Output is correct
26 Correct 21 ms 1116 KB Output is correct
27 Correct 178 ms 40488 KB Output is correct
28 Correct 175 ms 40440 KB Output is correct
29 Correct 142 ms 40404 KB Output is correct
30 Correct 161 ms 39968 KB Output is correct
31 Correct 292 ms 40952 KB Output is correct
32 Correct 809 ms 41328 KB Output is correct
33 Correct 408 ms 40912 KB Output is correct
34 Correct 459 ms 40304 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 685 ms 13240 KB Output is correct
37 Correct 2097 ms 40956 KB Output is correct
38 Correct 2173 ms 41244 KB Output is correct
39 Correct 1816 ms 39684 KB Output is correct
40 Correct 608 ms 21248 KB Output is correct
41 Correct 297 ms 11016 KB Output is correct
42 Correct 47 ms 2588 KB Output is correct
43 Correct 2091 ms 40496 KB Output is correct
44 Correct 1303 ms 40452 KB Output is correct
45 Correct 1702 ms 41284 KB Output is correct
46 Correct 1242 ms 41236 KB Output is correct
47 Correct 377 ms 39728 KB Output is correct
48 Correct 1320 ms 41700 KB Output is correct
49 Correct 1272 ms 41456 KB Output is correct
50 Correct 205 ms 39680 KB Output is correct
51 Correct 8 ms 1820 KB Output is correct
52 Correct 5 ms 1816 KB Output is correct
53 Correct 5 ms 1820 KB Output is correct
54 Correct 56 ms 1820 KB Output is correct
55 Correct 55 ms 1816 KB Output is correct
56 Correct 47 ms 1816 KB Output is correct
57 Correct 46 ms 13512 KB Output is correct
58 Correct 46 ms 13312 KB Output is correct
59 Correct 141 ms 13252 KB Output is correct
60 Correct 578 ms 13124 KB Output is correct
61 Correct 580 ms 13320 KB Output is correct
62 Correct 605 ms 13380 KB Output is correct
63 Correct 504 ms 13064 KB Output is correct
64 Correct 497 ms 13108 KB Output is correct
65 Correct 506 ms 13056 KB Output is correct
66 Correct 203 ms 13064 KB Output is correct
67 Correct 375 ms 13468 KB Output is correct
68 Correct 369 ms 13244 KB Output is correct
69 Correct 378 ms 13240 KB Output is correct
70 Correct 368 ms 13312 KB Output is correct
71 Correct 371 ms 13320 KB Output is correct
72 Correct 368 ms 13252 KB Output is correct
73 Correct 373 ms 13316 KB Output is correct
74 Correct 373 ms 13244 KB Output is correct
75 Correct 498 ms 41204 KB Output is correct
76 Correct 211 ms 41136 KB Output is correct
77 Correct 141 ms 40188 KB Output is correct
78 Correct 144 ms 40492 KB Output is correct
79 Correct 539 ms 41288 KB Output is correct
80 Correct 142 ms 39940 KB Output is correct
81 Correct 1997 ms 39748 KB Output is correct
82 Correct 1931 ms 40840 KB Output is correct
83 Correct 1925 ms 39928 KB Output is correct
84 Correct 2066 ms 40512 KB Output is correct
85 Correct 1985 ms 39716 KB Output is correct
86 Correct 2004 ms 41560 KB Output is correct
87 Correct 2289 ms 41232 KB Output is correct
88 Correct 1776 ms 44128 KB Output is correct
89 Correct 1691 ms 42988 KB Output is correct
90 Correct 1720 ms 43776 KB Output is correct
91 Correct 1771 ms 44952 KB Output is correct
92 Correct 1791 ms 44832 KB Output is correct
93 Correct 1318 ms 46872 KB Output is correct
94 Correct 1541 ms 47380 KB Output is correct
95 Correct 1332 ms 47684 KB Output is correct
96 Correct 1358 ms 47272 KB Output is correct
97 Correct 2180 ms 48228 KB Output is correct
98 Correct 859 ms 48096 KB Output is correct
99 Correct 1332 ms 48036 KB Output is correct
100 Correct 1252 ms 48156 KB Output is correct
101 Correct 1205 ms 47792 KB Output is correct
102 Correct 1342 ms 48096 KB Output is correct
103 Correct 1958 ms 47604 KB Output is correct
104 Correct 1353 ms 48132 KB Output is correct
105 Correct 741 ms 45572 KB Output is correct
106 Correct 1117 ms 48784 KB Output is correct
107 Correct 1136 ms 47936 KB Output is correct
108 Correct 1153 ms 49296 KB Output is correct
109 Correct 1152 ms 47608 KB Output is correct
110 Correct 1125 ms 48392 KB Output is correct
111 Correct 1123 ms 49144 KB Output is correct
112 Correct 1134 ms 48884 KB Output is correct
113 Correct 1134 ms 49140 KB Output is correct
114 Correct 1141 ms 48444 KB Output is correct
115 Correct 1130 ms 48928 KB Output is correct
116 Correct 1062 ms 48260 KB Output is correct