Submission #1107091

# Submission time Handle Problem Language Result Execution time Memory
1107091 2024-10-31T16:04:17 Z mispertion Circle selection (APIO18_circle_selection) C++17
19 / 100
3000 ms 198120 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define int ll
using ld = long double;
using pii = pair<int, int>;
#define F first
#define S second

const ld PI = 3.1415926535;
const int N = 5e5 + 2;
const int M = 2e6 + 1;
int mod = 998244353;
const int infi = INT_MAX;
const ll infl = LLONG_MAX;

int mult(int a, int b) {
    return a * 1LL * b % mod;
}

int sum(int a, int b) {
    if (a + b < 0)
        return a + b + mod;
    if (a + b >= mod)
        return a + b - mod;
    return a + b;
}


ll binpow(ll a, ll n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1) {
        return binpow(a, n - 1) * a % mod;
    } else {
        ll b = binpow(a, n / 2);
        return b * b % mod;
    }
}

struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        // Hash the first element
        size_t hash1 = hash<T1>{}(p.first);
        // Hash the second element
        size_t hash2 = hash<T2>{}(p.second);
        // Combine the two hash values
        return hash1
               ^ (hash2 + 0x9e3779b9 + (hash1 << 6)
                  + (hash1 >> 2));
    }
};

int n, ans[N];
int csz = 1e9+1;
set<pair<pii, pii>> cs;
gp_hash_table<pii, vector<pair<pii, pii>>, hash_pair> mp;

pii get(int x, int y){
    return {floor((ld)x / (ld)csz), floor((ld)y / (ld)csz)};
}

bool inter(pair<pii, pii> a, pair<pii, pii> b){
    return (((a.S.F - b.S.F) * (a.S.F - b.S.F) + (a.S.S - b.S.S) * (a.S.S - b.S.S)) <= (a.F.F + b.F.F) * (a.F.F + b.F.F));
}

void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x, y, r;
        cin >> x >> y >> r;
        cs.insert({{r, n - i + 1}, {x, y}});
        mp[get(x, y)].push_back({{r, n - i + 1}, {x, y}});
    }
    while(cs.size() > 0){
        auto e = *cs.rbegin();
        cs.erase(e);
        if(e.F.F <= csz / 2){
            csz = e.F.F;
            gp_hash_table<pii, vector<pair<pii, pii>>, hash_pair> np;
            for(auto bl : mp){
                for(auto crc : bl.S){
                    np[get(crc.S.F, crc.S.S)].push_back(crc);
                }
            }
            mp.swap(np);
        }        
        ans[n - e.F.S + 1] = n - e.F.S + 1;
        pii bl = get(e.S.F, e.S.S);
        for(int x = bl.F - 2; x <= bl.F + 2; x++){
            for(int y = bl.S - 2; y <= bl.S + 2; y++){
                if(mp.find({x, y}) == mp.end())
                    continue;
                for(auto crc : mp[{x, y}]){
                    if(inter(crc, e)){
                        if(ans[n - crc.F.S + 1] == 0){
                            ans[n - crc.F.S + 1] = n - e.F.S + 1;
                            cs.erase(crc);
                        }
                    }
                }
            }
        }
    }
    for(int i = 1; i <= n; i++)
        cout << ans[i] << ' ';
    cout << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 2 ms 848 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 4 ms 848 KB Output is correct
20 Correct 4 ms 972 KB Output is correct
21 Correct 12 ms 1572 KB Output is correct
22 Correct 23 ms 3736 KB Output is correct
23 Correct 21 ms 3692 KB Output is correct
24 Correct 23 ms 3396 KB Output is correct
25 Correct 21 ms 3476 KB Output is correct
26 Correct 22 ms 3484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 378 ms 58280 KB Output is correct
2 Correct 393 ms 56516 KB Output is correct
3 Correct 384 ms 59568 KB Output is correct
4 Correct 337 ms 52996 KB Output is correct
5 Correct 705 ms 104616 KB Output is correct
6 Correct 1583 ms 193356 KB Output is correct
7 Correct 1163 ms 191212 KB Output is correct
8 Correct 1289 ms 192040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 738 ms 59348 KB Output is correct
3 Execution timed out 3058 ms 198120 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 478 ms 139988 KB Output is correct
2 Correct 481 ms 138236 KB Output is correct
3 Execution timed out 3076 ms 55724 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 2 ms 848 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 4 ms 848 KB Output is correct
20 Correct 4 ms 972 KB Output is correct
21 Correct 12 ms 1572 KB Output is correct
22 Correct 23 ms 3736 KB Output is correct
23 Correct 21 ms 3692 KB Output is correct
24 Correct 23 ms 3396 KB Output is correct
25 Correct 21 ms 3476 KB Output is correct
26 Correct 22 ms 3484 KB Output is correct
27 Correct 46 ms 6244 KB Output is correct
28 Correct 11 ms 2504 KB Output is correct
29 Correct 8 ms 2672 KB Output is correct
30 Correct 49 ms 7248 KB Output is correct
31 Correct 50 ms 7864 KB Output is correct
32 Correct 53 ms 7104 KB Output is correct
33 Correct 97 ms 15100 KB Output is correct
34 Correct 87 ms 13708 KB Output is correct
35 Execution timed out 3048 ms 33444 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 2 ms 848 KB Output is correct
17 Correct 1 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 4 ms 848 KB Output is correct
20 Correct 4 ms 972 KB Output is correct
21 Correct 12 ms 1572 KB Output is correct
22 Correct 23 ms 3736 KB Output is correct
23 Correct 21 ms 3692 KB Output is correct
24 Correct 23 ms 3396 KB Output is correct
25 Correct 21 ms 3476 KB Output is correct
26 Correct 22 ms 3484 KB Output is correct
27 Correct 378 ms 58280 KB Output is correct
28 Correct 393 ms 56516 KB Output is correct
29 Correct 384 ms 59568 KB Output is correct
30 Correct 337 ms 52996 KB Output is correct
31 Correct 705 ms 104616 KB Output is correct
32 Correct 1583 ms 193356 KB Output is correct
33 Correct 1163 ms 191212 KB Output is correct
34 Correct 1289 ms 192040 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 738 ms 59348 KB Output is correct
37 Execution timed out 3058 ms 198120 KB Time limit exceeded
38 Halted 0 ms 0 KB -