Submission #397472

# Submission time Handle Problem Language Result Execution time Memory
397472 2021-05-02T09:36:49 Z AriaH Circle selection (APIO18_circle_selection) C++11
87 / 100
3000 ms 332072 KB
/* There's someone in my head but it's not me */ 
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
 
using namespace std;
 
typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second
 
const int N = 3e5 + 4, MOD = 1e9 + 7;
int n, X[N], Y[N], R[N], ord[N], xord[N], pos[N], ret[N]; vector<int> ids;

ll base[N];

int intersect(int i, int j)
{
    return (base[i] + base[j] + 2ll * (1ll * X[i] * X[j] + 1ll * Y[i] * Y[j] + 1ll * R[i] * R[j])) >= 0;
}
 
struct node : set<pii> {
    node *lc, *rc;
 
    node() : lc(nullptr), rc(nullptr) {}
 
    void build(int l = 1, int r = n + 1) {
        for (int i = l; i < r; i++) {
            this->insert({Y[xord[i]], xord[i]});
        }
        if (r - l < 2) return;
        int md = (l + r) >> 1;
        lc = new node(), rc = new node();
        lc->build(l, md), rc->build(md, r);
    }
 
    void remove(int &p, int &id, int l = 1, int r = n + 1) {
        this->erase({Y[id], id});
        if (r - l < 2) return;
        int md = (l + r) >> 1;
        if (p < md) lc->remove(p, id, l, md);
        else rc->remove(p, id, md, r);
    }
 
    void get(ll xl, ll xr, ll yl, ll yr, int &id, node* &rt, int l = 1, int r = n + 1) {
        if (xr <= X[xord[l]] || X[xord[r - 1]] + 1 <= xl || this->empty()) return;
        if (xl <= X[xord[l]] && X[xord[r - 1]] + 1 <= xr) {
            for (auto it = this->lower_bound({yl, -1e9}); it != this->end() && it->F <= yr; ) {
                auto x = *it;
                if (ret[x.S]) this->erase(x);
                else if (intersect(id, x.S)) ret[x.S] = id;
                it = this->upper_bound(x);
            }
            return;
        }
        int md = (l + r) >> 1;
        lc->get(xl, xr, yl, yr, id, rt, l, md), rc->get(xl, xr, yl, yr, id, rt, md, r);
    }
    
};
node* seg;
 
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) 
        scanf("%d%d%d", &X[i], &Y[i], &R[i]);
    for(int i = 1 ;i <= n; i ++)
    {
	base[i] = 1ll * R[i] * R[i] - 1ll * X[i] * X[i] - 1ll * Y[i] * Y[i];
    }
    iota(ord + 1, ord + n + 1, 1);
    iota(xord + 1, xord + n + 1, 1);
    sort(ord + 1, ord + n + 1, [&] (int i, int j) { return R[i] == R[j] ? i < j : R[i] > R[j]; });
    sort(xord + 1, xord + n + 1, [&] (int i, int j) { return X[i] < X[j]; });
    seg = new node(); seg->build();
    for (int i = 1; i <= n; i++) pos[xord[i]] = i;
    for (int _ = 1; _ <= n; _++) {
        int i = ord[_]; 
        if (ret[i]) continue;
        seg->get(X[i] - 2ll * R[i], X[i] + 2ll * R[i] + 1, Y[i] - 2ll * R[i], Y[i] + 2ll * R[i], i, seg);
    }
    for (int i = 1; i <= n; i++) printf("%d ", ret[i]);
    printf("\n");
    return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
circle_selection.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |         scanf("%d%d%d", &X[i], &Y[i], &R[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 336 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 304 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 336 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 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 5 ms 972 KB Output is correct
17 Correct 5 ms 1004 KB Output is correct
18 Correct 3 ms 972 KB Output is correct
19 Correct 13 ms 4604 KB Output is correct
20 Correct 14 ms 4508 KB Output is correct
21 Correct 14 ms 4576 KB Output is correct
22 Correct 15 ms 4572 KB Output is correct
23 Correct 17 ms 4592 KB Output is correct
24 Correct 15 ms 4556 KB Output is correct
25 Correct 16 ms 4524 KB Output is correct
26 Correct 15 ms 4572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1452 ms 331660 KB Output is correct
2 Correct 1389 ms 332072 KB Output is correct
3 Correct 1549 ms 331700 KB Output is correct
4 Correct 1411 ms 331276 KB Output is correct
5 Correct 1420 ms 331292 KB Output is correct
6 Correct 1556 ms 331412 KB Output is correct
7 Correct 1439 ms 331580 KB Output is correct
8 Correct 1455 ms 331616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 628 ms 103728 KB Output is correct
3 Correct 2335 ms 331696 KB Output is correct
4 Correct 2308 ms 331212 KB Output is correct
5 Correct 2256 ms 321748 KB Output is correct
6 Correct 916 ms 166096 KB Output is correct
7 Correct 398 ms 84048 KB Output is correct
8 Correct 56 ms 15684 KB Output is correct
9 Correct 2216 ms 331216 KB Output is correct
10 Correct 2186 ms 331252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2073 ms 331660 KB Output is correct
2 Correct 1792 ms 331324 KB Output is correct
3 Correct 1675 ms 330884 KB Output is correct
4 Correct 1803 ms 331204 KB Output is correct
5 Correct 1805 ms 331308 KB Output is correct
6 Correct 1618 ms 330564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 336 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 304 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 336 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 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 5 ms 972 KB Output is correct
17 Correct 5 ms 1004 KB Output is correct
18 Correct 3 ms 972 KB Output is correct
19 Correct 13 ms 4604 KB Output is correct
20 Correct 14 ms 4508 KB Output is correct
21 Correct 14 ms 4576 KB Output is correct
22 Correct 15 ms 4572 KB Output is correct
23 Correct 17 ms 4592 KB Output is correct
24 Correct 15 ms 4556 KB Output is correct
25 Correct 16 ms 4524 KB Output is correct
26 Correct 15 ms 4572 KB Output is correct
27 Correct 28 ms 9028 KB Output is correct
28 Correct 28 ms 9036 KB Output is correct
29 Correct 28 ms 9052 KB Output is correct
30 Correct 35 ms 8988 KB Output is correct
31 Correct 33 ms 9040 KB Output is correct
32 Correct 32 ms 9032 KB Output is correct
33 Correct 382 ms 103416 KB Output is correct
34 Correct 379 ms 103372 KB Output is correct
35 Correct 417 ms 103364 KB Output is correct
36 Correct 536 ms 103460 KB Output is correct
37 Correct 526 ms 103340 KB Output is correct
38 Correct 545 ms 103384 KB Output is correct
39 Correct 1283 ms 103348 KB Output is correct
40 Correct 1277 ms 103288 KB Output is correct
41 Correct 1271 ms 103236 KB Output is correct
42 Correct 464 ms 103252 KB Output is correct
43 Correct 399 ms 103328 KB Output is correct
44 Correct 394 ms 103360 KB Output is correct
45 Correct 404 ms 103380 KB Output is correct
46 Correct 418 ms 103336 KB Output is correct
47 Correct 415 ms 103336 KB Output is correct
48 Correct 393 ms 103360 KB Output is correct
49 Correct 394 ms 103392 KB Output is correct
50 Correct 411 ms 103336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 336 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 304 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 336 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 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 5 ms 972 KB Output is correct
17 Correct 5 ms 1004 KB Output is correct
18 Correct 3 ms 972 KB Output is correct
19 Correct 13 ms 4604 KB Output is correct
20 Correct 14 ms 4508 KB Output is correct
21 Correct 14 ms 4576 KB Output is correct
22 Correct 15 ms 4572 KB Output is correct
23 Correct 17 ms 4592 KB Output is correct
24 Correct 15 ms 4556 KB Output is correct
25 Correct 16 ms 4524 KB Output is correct
26 Correct 15 ms 4572 KB Output is correct
27 Correct 1452 ms 331660 KB Output is correct
28 Correct 1389 ms 332072 KB Output is correct
29 Correct 1549 ms 331700 KB Output is correct
30 Correct 1411 ms 331276 KB Output is correct
31 Correct 1420 ms 331292 KB Output is correct
32 Correct 1556 ms 331412 KB Output is correct
33 Correct 1439 ms 331580 KB Output is correct
34 Correct 1455 ms 331616 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 628 ms 103728 KB Output is correct
37 Correct 2335 ms 331696 KB Output is correct
38 Correct 2308 ms 331212 KB Output is correct
39 Correct 2256 ms 321748 KB Output is correct
40 Correct 916 ms 166096 KB Output is correct
41 Correct 398 ms 84048 KB Output is correct
42 Correct 56 ms 15684 KB Output is correct
43 Correct 2216 ms 331216 KB Output is correct
44 Correct 2186 ms 331252 KB Output is correct
45 Correct 2073 ms 331660 KB Output is correct
46 Correct 1792 ms 331324 KB Output is correct
47 Correct 1675 ms 330884 KB Output is correct
48 Correct 1803 ms 331204 KB Output is correct
49 Correct 1805 ms 331308 KB Output is correct
50 Correct 1618 ms 330564 KB Output is correct
51 Correct 28 ms 9028 KB Output is correct
52 Correct 28 ms 9036 KB Output is correct
53 Correct 28 ms 9052 KB Output is correct
54 Correct 35 ms 8988 KB Output is correct
55 Correct 33 ms 9040 KB Output is correct
56 Correct 32 ms 9032 KB Output is correct
57 Correct 382 ms 103416 KB Output is correct
58 Correct 379 ms 103372 KB Output is correct
59 Correct 417 ms 103364 KB Output is correct
60 Correct 536 ms 103460 KB Output is correct
61 Correct 526 ms 103340 KB Output is correct
62 Correct 545 ms 103384 KB Output is correct
63 Correct 1283 ms 103348 KB Output is correct
64 Correct 1277 ms 103288 KB Output is correct
65 Correct 1271 ms 103236 KB Output is correct
66 Correct 464 ms 103252 KB Output is correct
67 Correct 399 ms 103328 KB Output is correct
68 Correct 394 ms 103360 KB Output is correct
69 Correct 404 ms 103380 KB Output is correct
70 Correct 418 ms 103336 KB Output is correct
71 Correct 415 ms 103336 KB Output is correct
72 Correct 393 ms 103360 KB Output is correct
73 Correct 394 ms 103392 KB Output is correct
74 Correct 411 ms 103336 KB Output is correct
75 Correct 1586 ms 331144 KB Output is correct
76 Correct 1438 ms 331408 KB Output is correct
77 Correct 1415 ms 331316 KB Output is correct
78 Correct 1398 ms 331140 KB Output is correct
79 Correct 1635 ms 331204 KB Output is correct
80 Correct 1391 ms 331032 KB Output is correct
81 Correct 2144 ms 331292 KB Output is correct
82 Correct 2041 ms 331128 KB Output is correct
83 Correct 2082 ms 330992 KB Output is correct
84 Correct 2332 ms 331076 KB Output is correct
85 Correct 2254 ms 330960 KB Output is correct
86 Correct 2125 ms 330972 KB Output is correct
87 Execution timed out 3110 ms 330228 KB Time limit exceeded
88 Halted 0 ms 0 KB -