Submission #579066

# Submission time Handle Problem Language Result Execution time Memory
579066 2022-06-18T11:08:06 Z noedit Circle selection (APIO18_circle_selection) C++17
37 / 100
3000 ms 134008 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
#pragma GCC optimize("O0")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#define sz(x) (x.size())
using namespace std;
using namespace __gnu_pbds;

template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
//#define int long long

const int INF = 1e9;
const int MAXN = 3e5 + 10;

pair<pair<int, int>, pair<int, int> > in[MAXN];

int X[MAXN], Y[MAXN], R[MAXN];
int ind[MAXN];
int ans[MAXN];
int ri[MAXN];

inline ll sq(ll x)
{
    return x * x;
}

bool check(int i, int j)
{
    return sq(X[i] - X[j]) + sq(Y[i] - Y[j]) <= sq(R[i] + R[j]);
}

inline bool isrange(int x, int y)
{
    if (x < 0 || y < 0)
        return false;
    return true;
}

ll trans(int x, int y)
{
    return ((ll)x * 1ll * INF) + y;
}

bool cmp(pair<pair<int, int>, pair<int, int> >& p1, pair<pair<int, int>, pair<int, int> >& p2)
{
    if (p1.first.first == p2.first.first)
    {
        return p1.first.second < p2.first.second;
    }
    else
    {
        return p1.first.first > p2.first.first;
    }
}

unordered_map<ll, vector<int> > mp;

void solve()
{
    int n;
    cin >> n;
    int i;
    for (i = 1; i <= n; i++)
    {
        cin >> in[i].second.first >> in[i].second.second >> in[i].first.first;
        in[i].first.second = i;
    }
    sort(in + 1, in + n + 1, cmp);
    for (i = 1; i <= n; i++)
    {
        tie(X[i], Y[i], R[i], ind[i]) = make_tuple(in[i].second.first + INF, in[i].second.second + INF, in[i].first.first, in[i].first.second);
    }
    int k;
    int s, e;
    e = 0;
    for (k = 30; k >= 0; k--)
    {
        int r = (1 << k);
        s = e + 1;
        if (R[s] < r / 2)
        {
            continue;
        }
        mp.clear();
        e = 0;
        for (i = s; i <= n; i++)
        {
            if (ans[i])
            {
                continue;
            }
            int x, y;
            x = X[i] >> k;
            y = Y[i] >> k;
            if (R[i] < r / 2 && !e)
            {
                e = i - 1;
            }
            for (int xx = x - 1; xx <= x + 1; xx++)
            {
                for (int yy = y - 1; yy <= y + 1; yy++)
                {
                    mp[(ll)xx << 31LL + yy].push_back(i);
                }
            }
        }
        if (e == 0)
        {
            e = n;
        }
        for (i = s; i <= e; i++)
        {
            if (ans[i])
            {
                continue;
            }
            ans[i] = i;
            int x = X[i] >> k;
            int y = Y[i] >> k;
            for (int xx = x - 1; xx <= x + 1; xx++)
            {
                for (int yy = y - 1; yy <= y + 1; yy++)
                {
                    ll t = ((ll)xx << 31LL + yy);
                    for (auto& c : mp[t])
                    {
                        if (!ans[c] && check(c, i))
                        {
                            ans[c] = i;
                        }
                    }
                }
            }
        }
    }
    for (i = 1; i <= n; i++)
    {
        ri[ind[i]] = i;
    }
    for (i = 1; i <= n; i++)
    {
        cout << ind[ans[ri[i]]] << ' ';
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}

Compilation message

circle_selection.cpp: In function 'void solve()':
circle_selection.cpp:109:39: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
  109 |                     mp[(ll)xx << 31LL + yy].push_back(i);
      |                                  ~~~~~^~~~
circle_selection.cpp:130:44: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
  130 |                     ll t = ((ll)xx << 31LL + yy);
      |                                       ~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 500 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 4 ms 980 KB Output is correct
21 Correct 4 ms 900 KB Output is correct
22 Correct 20 ms 3716 KB Output is correct
23 Correct 21 ms 1884 KB Output is correct
24 Correct 29 ms 3776 KB Output is correct
25 Correct 25 ms 4008 KB Output is correct
26 Correct 31 ms 3792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 204 ms 24732 KB Output is correct
2 Correct 237 ms 23624 KB Output is correct
3 Correct 217 ms 22952 KB Output is correct
4 Correct 204 ms 23860 KB Output is correct
5 Correct 364 ms 30764 KB Output is correct
6 Execution timed out 3044 ms 47132 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1691 ms 23324 KB Output is correct
3 Execution timed out 3086 ms 56952 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3092 ms 134008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 500 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 4 ms 980 KB Output is correct
21 Correct 4 ms 900 KB Output is correct
22 Correct 20 ms 3716 KB Output is correct
23 Correct 21 ms 1884 KB Output is correct
24 Correct 29 ms 3776 KB Output is correct
25 Correct 25 ms 4008 KB Output is correct
26 Correct 31 ms 3792 KB Output is correct
27 Correct 9 ms 1364 KB Output is correct
28 Correct 8 ms 1360 KB Output is correct
29 Correct 8 ms 1364 KB Output is correct
30 Correct 44 ms 5272 KB Output is correct
31 Correct 61 ms 6832 KB Output is correct
32 Correct 58 ms 6868 KB Output is correct
33 Correct 86 ms 8148 KB Output is correct
34 Correct 74 ms 8236 KB Output is correct
35 Correct 78 ms 7976 KB Output is correct
36 Correct 1879 ms 53896 KB Output is correct
37 Correct 1772 ms 53596 KB Output is correct
38 Correct 2015 ms 50384 KB Output is correct
39 Correct 1187 ms 12076 KB Output is correct
40 Correct 1240 ms 12032 KB Output is correct
41 Correct 1271 ms 12096 KB Output is correct
42 Correct 629 ms 10780 KB Output is correct
43 Correct 1916 ms 62028 KB Output is correct
44 Correct 1947 ms 62044 KB Output is correct
45 Correct 2081 ms 62004 KB Output is correct
46 Correct 1867 ms 62268 KB Output is correct
47 Correct 1780 ms 62100 KB Output is correct
48 Correct 1657 ms 62268 KB Output is correct
49 Correct 1898 ms 62296 KB Output is correct
50 Correct 1685 ms 62308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 500 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 4 ms 980 KB Output is correct
21 Correct 4 ms 900 KB Output is correct
22 Correct 20 ms 3716 KB Output is correct
23 Correct 21 ms 1884 KB Output is correct
24 Correct 29 ms 3776 KB Output is correct
25 Correct 25 ms 4008 KB Output is correct
26 Correct 31 ms 3792 KB Output is correct
27 Correct 204 ms 24732 KB Output is correct
28 Correct 237 ms 23624 KB Output is correct
29 Correct 217 ms 22952 KB Output is correct
30 Correct 204 ms 23860 KB Output is correct
31 Correct 364 ms 30764 KB Output is correct
32 Execution timed out 3044 ms 47132 KB Time limit exceeded
33 Halted 0 ms 0 KB -