Submission #66132

# Submission time Handle Problem Language Result Execution time Memory
66132 2018-08-09T18:56:01 Z Benq Circle selection (APIO18_circle_selection) C++11
100 / 100
2157 ms 438336 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 300001;

const int CON = 1000000000;
int n, r[MX], ans[MX];
pi p[MX];
set<pi> S;
map<int,int> m; vi rm;
vpi tmp[MX];

ll sq(ll x) { return x*x; }
ll dist(pi a, pi b) { a.f -= b.f, a.s -= b.s; return (ll)a.f*a.f+(ll)a.s*a.s; }
bool inter(int a, int b) { return dist(p[a],p[b]) <= sq(r[a]+r[b]); }

void init() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    FOR(i,1,n+1) {
        //p[i].f = rand() % (2*CON);
        //p[i].s = rand() % (2*CON);
        //r[i] = rand() % CON+1;
        cin >> p[i].f >> p[i].s >> r[i];
        p[i].f += CON; p[i].s += CON;
        S.insert({r[i],-i});
    }
}

ll crad = INF;

void del(int x, int e) { ans[x] = e; S.erase({r[x],-x}); }

pi getPos(int x) { return {p[x].f/crad,p[x].s/crad}; }

void recalc() {
    F0R(i,sz(m)) tmp[i].clear();
    m.clear(), rm.clear();
    FOR(i,1,n+1) if (!ans[i]) m[getPos(i).f] = 0;
    for (auto& a: m) { a.s = sz(rm); rm.pb(a.f); }
    FOR(i,1,n+1) if (!ans[i]) {
        pi P = getPos(i);
        tmp[m[P.f]].pb({P.s,i});
    }
    F0R(i,sz(m)) sort(all(tmp[i]));
}

void solve() {
    pi x = *S.rbegin(); x.s *= -1; 
    if (2*x.f <= crad) { crad = x.f; recalc(); }
    
    pi pos = getPos(x.s);
    
    int z = 0;
    for (int t = lb(all(rm),pos.f-2)-rm.begin(); 
        t < sz(rm) && abs(rm[t]-pos.f) <= 2; t ++) 
        for (int t2 = lb(all(tmp[t]),mp(pos.s-2,-MOD))-tmp[t].begin(); 
            t2 < sz(tmp[t]) && abs(tmp[t][t2].f-pos.s) <= 2; t2++) {
            if (!ans[tmp[t][t2].s] && inter(x.s,tmp[t][t2].s)) {
                del(tmp[t][t2].s,x.s);
                z ++;
            }
            // if (x.s == 3905) cout << "HUH " << t << " " << t2 << " " << tmp[t][t2].s << "\n";
        }
            
    /*if (z == 0) {
        cout << "OOPS " << inter(x.s,x.s) << "\n";
        cout << "HUH " << x.s << " " << p[x.s].f << " " << p[x.s].s << " " << ans[x.s] << " " << r[x.s] << "\n";
        cout << pos.f << " " << pos.s << " " << crad << "\n";
        cout << m[pos.f] << "\n";
        cout << lb(all(rm),pos.f-2)-rm.begin() << "\n";
        exit(0);
    }*/
}

int main() {
    init();
    while (sz(S)) solve();
    FOR(i,1,n+1) cout << ans[i] << " ";
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 10 ms 7492 KB Output is correct
4 Correct 10 ms 7492 KB Output is correct
5 Correct 10 ms 7592 KB Output is correct
6 Correct 9 ms 7596 KB Output is correct
7 Correct 9 ms 7596 KB Output is correct
8 Correct 8 ms 7596 KB Output is correct
9 Correct 10 ms 7608 KB Output is correct
10 Correct 7 ms 7736 KB Output is correct
11 Correct 10 ms 7736 KB Output is correct
12 Correct 9 ms 7736 KB Output is correct
13 Correct 8 ms 7736 KB Output is correct
14 Correct 9 ms 7736 KB Output is correct
15 Correct 10 ms 7752 KB Output is correct
16 Correct 10 ms 7836 KB Output is correct
17 Correct 9 ms 7868 KB Output is correct
18 Correct 11 ms 7916 KB Output is correct
19 Correct 14 ms 8380 KB Output is correct
20 Correct 15 ms 8660 KB Output is correct
21 Correct 14 ms 8692 KB Output is correct
22 Correct 19 ms 8984 KB Output is correct
23 Correct 22 ms 8988 KB Output is correct
24 Correct 19 ms 9288 KB Output is correct
25 Correct 25 ms 9644 KB Output is correct
26 Correct 18 ms 9660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 783 ms 32484 KB Output is correct
2 Correct 823 ms 32484 KB Output is correct
3 Correct 727 ms 32484 KB Output is correct
4 Correct 724 ms 32940 KB Output is correct
5 Correct 857 ms 33748 KB Output is correct
6 Correct 1316 ms 42852 KB Output is correct
7 Correct 990 ms 42852 KB Output is correct
8 Correct 1119 ms 42852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 42852 KB Output is correct
2 Correct 340 ms 42852 KB Output is correct
3 Correct 1537 ms 46108 KB Output is correct
4 Correct 1652 ms 54488 KB Output is correct
5 Correct 1364 ms 61552 KB Output is correct
6 Correct 536 ms 61552 KB Output is correct
7 Correct 289 ms 61552 KB Output is correct
8 Correct 52 ms 61552 KB Output is correct
9 Correct 1597 ms 78052 KB Output is correct
10 Correct 1320 ms 86520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 958 ms 89488 KB Output is correct
2 Correct 1056 ms 112164 KB Output is correct
3 Correct 680 ms 112164 KB Output is correct
4 Correct 1155 ms 126360 KB Output is correct
5 Correct 1119 ms 134876 KB Output is correct
6 Correct 783 ms 134876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 10 ms 7492 KB Output is correct
4 Correct 10 ms 7492 KB Output is correct
5 Correct 10 ms 7592 KB Output is correct
6 Correct 9 ms 7596 KB Output is correct
7 Correct 9 ms 7596 KB Output is correct
8 Correct 8 ms 7596 KB Output is correct
9 Correct 10 ms 7608 KB Output is correct
10 Correct 7 ms 7736 KB Output is correct
11 Correct 10 ms 7736 KB Output is correct
12 Correct 9 ms 7736 KB Output is correct
13 Correct 8 ms 7736 KB Output is correct
14 Correct 9 ms 7736 KB Output is correct
15 Correct 10 ms 7752 KB Output is correct
16 Correct 10 ms 7836 KB Output is correct
17 Correct 9 ms 7868 KB Output is correct
18 Correct 11 ms 7916 KB Output is correct
19 Correct 14 ms 8380 KB Output is correct
20 Correct 15 ms 8660 KB Output is correct
21 Correct 14 ms 8692 KB Output is correct
22 Correct 19 ms 8984 KB Output is correct
23 Correct 22 ms 8988 KB Output is correct
24 Correct 19 ms 9288 KB Output is correct
25 Correct 25 ms 9644 KB Output is correct
26 Correct 18 ms 9660 KB Output is correct
27 Correct 22 ms 134876 KB Output is correct
28 Correct 19 ms 134876 KB Output is correct
29 Correct 26 ms 134876 KB Output is correct
30 Correct 29 ms 134876 KB Output is correct
31 Correct 34 ms 134876 KB Output is correct
32 Correct 35 ms 134876 KB Output is correct
33 Correct 196 ms 134876 KB Output is correct
34 Correct 255 ms 134876 KB Output is correct
35 Correct 209 ms 134876 KB Output is correct
36 Correct 378 ms 134876 KB Output is correct
37 Correct 443 ms 134876 KB Output is correct
38 Correct 483 ms 134876 KB Output is correct
39 Correct 616 ms 134876 KB Output is correct
40 Correct 447 ms 134876 KB Output is correct
41 Correct 434 ms 134876 KB Output is correct
42 Correct 185 ms 134876 KB Output is correct
43 Correct 278 ms 139848 KB Output is correct
44 Correct 297 ms 142500 KB Output is correct
45 Correct 327 ms 145240 KB Output is correct
46 Correct 265 ms 147648 KB Output is correct
47 Correct 277 ms 150364 KB Output is correct
48 Correct 297 ms 152936 KB Output is correct
49 Correct 291 ms 155552 KB Output is correct
50 Correct 298 ms 158140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 10 ms 7492 KB Output is correct
4 Correct 10 ms 7492 KB Output is correct
5 Correct 10 ms 7592 KB Output is correct
6 Correct 9 ms 7596 KB Output is correct
7 Correct 9 ms 7596 KB Output is correct
8 Correct 8 ms 7596 KB Output is correct
9 Correct 10 ms 7608 KB Output is correct
10 Correct 7 ms 7736 KB Output is correct
11 Correct 10 ms 7736 KB Output is correct
12 Correct 9 ms 7736 KB Output is correct
13 Correct 8 ms 7736 KB Output is correct
14 Correct 9 ms 7736 KB Output is correct
15 Correct 10 ms 7752 KB Output is correct
16 Correct 10 ms 7836 KB Output is correct
17 Correct 9 ms 7868 KB Output is correct
18 Correct 11 ms 7916 KB Output is correct
19 Correct 14 ms 8380 KB Output is correct
20 Correct 15 ms 8660 KB Output is correct
21 Correct 14 ms 8692 KB Output is correct
22 Correct 19 ms 8984 KB Output is correct
23 Correct 22 ms 8988 KB Output is correct
24 Correct 19 ms 9288 KB Output is correct
25 Correct 25 ms 9644 KB Output is correct
26 Correct 18 ms 9660 KB Output is correct
27 Correct 783 ms 32484 KB Output is correct
28 Correct 823 ms 32484 KB Output is correct
29 Correct 727 ms 32484 KB Output is correct
30 Correct 724 ms 32940 KB Output is correct
31 Correct 857 ms 33748 KB Output is correct
32 Correct 1316 ms 42852 KB Output is correct
33 Correct 990 ms 42852 KB Output is correct
34 Correct 1119 ms 42852 KB Output is correct
35 Correct 8 ms 42852 KB Output is correct
36 Correct 340 ms 42852 KB Output is correct
37 Correct 1537 ms 46108 KB Output is correct
38 Correct 1652 ms 54488 KB Output is correct
39 Correct 1364 ms 61552 KB Output is correct
40 Correct 536 ms 61552 KB Output is correct
41 Correct 289 ms 61552 KB Output is correct
42 Correct 52 ms 61552 KB Output is correct
43 Correct 1597 ms 78052 KB Output is correct
44 Correct 1320 ms 86520 KB Output is correct
45 Correct 958 ms 89488 KB Output is correct
46 Correct 1056 ms 112164 KB Output is correct
47 Correct 680 ms 112164 KB Output is correct
48 Correct 1155 ms 126360 KB Output is correct
49 Correct 1119 ms 134876 KB Output is correct
50 Correct 783 ms 134876 KB Output is correct
51 Correct 22 ms 134876 KB Output is correct
52 Correct 19 ms 134876 KB Output is correct
53 Correct 26 ms 134876 KB Output is correct
54 Correct 29 ms 134876 KB Output is correct
55 Correct 34 ms 134876 KB Output is correct
56 Correct 35 ms 134876 KB Output is correct
57 Correct 196 ms 134876 KB Output is correct
58 Correct 255 ms 134876 KB Output is correct
59 Correct 209 ms 134876 KB Output is correct
60 Correct 378 ms 134876 KB Output is correct
61 Correct 443 ms 134876 KB Output is correct
62 Correct 483 ms 134876 KB Output is correct
63 Correct 616 ms 134876 KB Output is correct
64 Correct 447 ms 134876 KB Output is correct
65 Correct 434 ms 134876 KB Output is correct
66 Correct 185 ms 134876 KB Output is correct
67 Correct 278 ms 139848 KB Output is correct
68 Correct 297 ms 142500 KB Output is correct
69 Correct 327 ms 145240 KB Output is correct
70 Correct 265 ms 147648 KB Output is correct
71 Correct 277 ms 150364 KB Output is correct
72 Correct 297 ms 152936 KB Output is correct
73 Correct 291 ms 155552 KB Output is correct
74 Correct 298 ms 158140 KB Output is correct
75 Correct 880 ms 175424 KB Output is correct
76 Correct 833 ms 182864 KB Output is correct
77 Correct 704 ms 190204 KB Output is correct
78 Correct 997 ms 198448 KB Output is correct
79 Correct 1074 ms 207584 KB Output is correct
80 Correct 869 ms 216320 KB Output is correct
81 Correct 1713 ms 227700 KB Output is correct
82 Correct 1945 ms 236744 KB Output is correct
83 Correct 1712 ms 243892 KB Output is correct
84 Correct 1498 ms 248476 KB Output is correct
85 Correct 1550 ms 257196 KB Output is correct
86 Correct 1826 ms 266304 KB Output is correct
87 Correct 1231 ms 272688 KB Output is correct
88 Correct 1731 ms 280860 KB Output is correct
89 Correct 1476 ms 284080 KB Output is correct
90 Correct 1840 ms 285788 KB Output is correct
91 Correct 1583 ms 288864 KB Output is correct
92 Correct 1478 ms 290912 KB Output is correct
93 Correct 1670 ms 309304 KB Output is correct
94 Correct 707 ms 309304 KB Output is correct
95 Correct 1854 ms 319880 KB Output is correct
96 Correct 2157 ms 324272 KB Output is correct
97 Correct 854 ms 324272 KB Output is correct
98 Correct 1398 ms 325412 KB Output is correct
99 Correct 1714 ms 339880 KB Output is correct
100 Correct 1534 ms 345088 KB Output is correct
101 Correct 1309 ms 345088 KB Output is correct
102 Correct 1739 ms 358168 KB Output is correct
103 Correct 890 ms 358168 KB Output is correct
104 Correct 2076 ms 368560 KB Output is correct
105 Correct 684 ms 368560 KB Output is correct
106 Correct 1081 ms 375312 KB Output is correct
107 Correct 1126 ms 383132 KB Output is correct
108 Correct 1146 ms 388524 KB Output is correct
109 Correct 1232 ms 393600 KB Output is correct
110 Correct 1327 ms 398548 KB Output is correct
111 Correct 1223 ms 403632 KB Output is correct
112 Correct 1314 ms 410836 KB Output is correct
113 Correct 1239 ms 418444 KB Output is correct
114 Correct 1222 ms 425720 KB Output is correct
115 Correct 1436 ms 430636 KB Output is correct
116 Correct 1383 ms 438336 KB Output is correct