Submission #397474

# Submission time Handle Problem Language Result Execution time Memory
397474 2021-05-02T09:38:06 Z AriaH Circle selection (APIO18_circle_selection) C++11
87 / 100
3000 ms 331584 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 332 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 332 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 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 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 3 ms 972 KB Output is correct
17 Correct 3 ms 972 KB Output is correct
18 Correct 4 ms 972 KB Output is correct
19 Correct 13 ms 4428 KB Output is correct
20 Correct 13 ms 4440 KB Output is correct
21 Correct 20 ms 4436 KB Output is correct
22 Correct 16 ms 4436 KB Output is correct
23 Correct 18 ms 4444 KB Output is correct
24 Correct 16 ms 4444 KB Output is correct
25 Correct 15 ms 4448 KB Output is correct
26 Correct 15 ms 4428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1345 ms 331392 KB Output is correct
2 Correct 1415 ms 331408 KB Output is correct
3 Correct 1400 ms 331180 KB Output is correct
4 Correct 1352 ms 331584 KB Output is correct
5 Correct 1405 ms 330872 KB Output is correct
6 Correct 1519 ms 331096 KB Output is correct
7 Correct 1378 ms 331076 KB Output is correct
8 Correct 1422 ms 330956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 619 ms 103084 KB Output is correct
3 Correct 2234 ms 331040 KB Output is correct
4 Correct 2266 ms 331036 KB Output is correct
5 Correct 2155 ms 321468 KB Output is correct
6 Correct 873 ms 165896 KB Output is correct
7 Correct 375 ms 83844 KB Output is correct
8 Correct 55 ms 15612 KB Output is correct
9 Correct 2189 ms 331008 KB Output is correct
10 Correct 2180 ms 330996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2049 ms 331132 KB Output is correct
2 Correct 1746 ms 331024 KB Output is correct
3 Correct 1675 ms 330676 KB Output is correct
4 Correct 1813 ms 331020 KB Output is correct
5 Correct 1777 ms 331088 KB Output is correct
6 Correct 1585 ms 330436 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 332 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 332 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 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 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 3 ms 972 KB Output is correct
17 Correct 3 ms 972 KB Output is correct
18 Correct 4 ms 972 KB Output is correct
19 Correct 13 ms 4428 KB Output is correct
20 Correct 13 ms 4440 KB Output is correct
21 Correct 20 ms 4436 KB Output is correct
22 Correct 16 ms 4436 KB Output is correct
23 Correct 18 ms 4444 KB Output is correct
24 Correct 16 ms 4444 KB Output is correct
25 Correct 15 ms 4448 KB Output is correct
26 Correct 15 ms 4428 KB Output is correct
27 Correct 29 ms 9028 KB Output is correct
28 Correct 36 ms 8972 KB Output is correct
29 Correct 28 ms 9048 KB Output is correct
30 Correct 35 ms 8996 KB Output is correct
31 Correct 33 ms 8988 KB Output is correct
32 Correct 35 ms 8944 KB Output is correct
33 Correct 377 ms 103056 KB Output is correct
34 Correct 379 ms 103268 KB Output is correct
35 Correct 412 ms 103080 KB Output is correct
36 Correct 522 ms 103264 KB Output is correct
37 Correct 519 ms 103116 KB Output is correct
38 Correct 557 ms 103088 KB Output is correct
39 Correct 1280 ms 103088 KB Output is correct
40 Correct 1372 ms 103012 KB Output is correct
41 Correct 1271 ms 103088 KB Output is correct
42 Correct 487 ms 102920 KB Output is correct
43 Correct 414 ms 103072 KB Output is correct
44 Correct 398 ms 103152 KB Output is correct
45 Correct 405 ms 103076 KB Output is correct
46 Correct 437 ms 103140 KB Output is correct
47 Correct 413 ms 103172 KB Output is correct
48 Correct 387 ms 103212 KB Output is correct
49 Correct 395 ms 103084 KB Output is correct
50 Correct 404 ms 103108 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 332 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 332 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 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 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 3 ms 972 KB Output is correct
17 Correct 3 ms 972 KB Output is correct
18 Correct 4 ms 972 KB Output is correct
19 Correct 13 ms 4428 KB Output is correct
20 Correct 13 ms 4440 KB Output is correct
21 Correct 20 ms 4436 KB Output is correct
22 Correct 16 ms 4436 KB Output is correct
23 Correct 18 ms 4444 KB Output is correct
24 Correct 16 ms 4444 KB Output is correct
25 Correct 15 ms 4448 KB Output is correct
26 Correct 15 ms 4428 KB Output is correct
27 Correct 1345 ms 331392 KB Output is correct
28 Correct 1415 ms 331408 KB Output is correct
29 Correct 1400 ms 331180 KB Output is correct
30 Correct 1352 ms 331584 KB Output is correct
31 Correct 1405 ms 330872 KB Output is correct
32 Correct 1519 ms 331096 KB Output is correct
33 Correct 1378 ms 331076 KB Output is correct
34 Correct 1422 ms 330956 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 619 ms 103084 KB Output is correct
37 Correct 2234 ms 331040 KB Output is correct
38 Correct 2266 ms 331036 KB Output is correct
39 Correct 2155 ms 321468 KB Output is correct
40 Correct 873 ms 165896 KB Output is correct
41 Correct 375 ms 83844 KB Output is correct
42 Correct 55 ms 15612 KB Output is correct
43 Correct 2189 ms 331008 KB Output is correct
44 Correct 2180 ms 330996 KB Output is correct
45 Correct 2049 ms 331132 KB Output is correct
46 Correct 1746 ms 331024 KB Output is correct
47 Correct 1675 ms 330676 KB Output is correct
48 Correct 1813 ms 331020 KB Output is correct
49 Correct 1777 ms 331088 KB Output is correct
50 Correct 1585 ms 330436 KB Output is correct
51 Correct 29 ms 9028 KB Output is correct
52 Correct 36 ms 8972 KB Output is correct
53 Correct 28 ms 9048 KB Output is correct
54 Correct 35 ms 8996 KB Output is correct
55 Correct 33 ms 8988 KB Output is correct
56 Correct 35 ms 8944 KB Output is correct
57 Correct 377 ms 103056 KB Output is correct
58 Correct 379 ms 103268 KB Output is correct
59 Correct 412 ms 103080 KB Output is correct
60 Correct 522 ms 103264 KB Output is correct
61 Correct 519 ms 103116 KB Output is correct
62 Correct 557 ms 103088 KB Output is correct
63 Correct 1280 ms 103088 KB Output is correct
64 Correct 1372 ms 103012 KB Output is correct
65 Correct 1271 ms 103088 KB Output is correct
66 Correct 487 ms 102920 KB Output is correct
67 Correct 414 ms 103072 KB Output is correct
68 Correct 398 ms 103152 KB Output is correct
69 Correct 405 ms 103076 KB Output is correct
70 Correct 437 ms 103140 KB Output is correct
71 Correct 413 ms 103172 KB Output is correct
72 Correct 387 ms 103212 KB Output is correct
73 Correct 395 ms 103084 KB Output is correct
74 Correct 404 ms 103108 KB Output is correct
75 Correct 1575 ms 331052 KB Output is correct
76 Correct 1471 ms 331136 KB Output is correct
77 Correct 1461 ms 331264 KB Output is correct
78 Correct 1421 ms 330800 KB Output is correct
79 Correct 1656 ms 331024 KB Output is correct
80 Correct 1430 ms 330988 KB Output is correct
81 Correct 2161 ms 331020 KB Output is correct
82 Correct 2082 ms 331004 KB Output is correct
83 Correct 2197 ms 330988 KB Output is correct
84 Correct 2476 ms 330984 KB Output is correct
85 Correct 2229 ms 331012 KB Output is correct
86 Correct 2148 ms 331104 KB Output is correct
87 Execution timed out 3097 ms 328984 KB Time limit exceeded
88 Halted 0 ms 0 KB -