Submission #397548

# Submission time Handle Problem Language Result Execution time Memory
397548 2021-05-02T11:08:10 Z AriaH Circle selection (APIO18_circle_selection) C++11
87 / 100
3000 ms 396632 KB
/* There's someone in my head but it's not me */ 
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;

#define all(x) x.begin(), x.end()

#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second
#define lc                          id << 1
#define rc                          lc | 1

const int N = 3e5 + 4, MOD = 1e9 + 7;
int n, X[N], Y[N], R[N], ord[N], ret[N], id[N]; ll base[N];
set<pii> seg[N << 1];

vector < pii > vec[N << 1];

vector <ll> cm;

bool cmp(int i, int j) {
	if(R[i] == R[j]) return i < j;
    return R[i] > R[j];
}

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;
}

int lwr(ll x) {
    return lower_bound(all(cm), x) - cm.begin();
}

void add(int pos, pii x)
{
    pos += n;
    vec[pos].push_back(x);
}

void get(int ql, int qr, ll yl, ll yr, int p) {
    ql += n, qr += n + 1;
    while (qr - ql > 0) {
        if (ql & 1) {
            for (auto it = seg[ql].lower_bound({yl, -1e9}); it != seg[ql].end() && it->F <= yr; ) {
                auto x = *it;
                if (ret[x.S]) seg[ql].erase(x);
                else if (intersect(p, x.S)) ret[x.S] = p, seg[ql].erase(x);
                it = seg[ql].upper_bound(x);
            }
            ql++;
        } 
        if (qr & 1) {
            qr--;
            for (auto it = seg[qr].lower_bound({yl, -1e9}); it != seg[qr].end() && it->F <= yr; ) {
                auto x = *it;
                if (ret[x.S]) seg[qr].erase(x);
                else if (intersect(p, x.S)) ret[x.S] = p, seg[qr].erase(x);
                it = seg[qr].upper_bound(x);
            }
        }
        qr >>= 1, ql >>= 1;
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) 
        scanf("%d%d%d", &X[i], &Y[i], &R[i]), base[i] = 1ll * R[i] * R[i] - 1ll * X[i] * X[i] - 1ll * Y[i] * Y[i], cm.push_back(X[i]), ord[i] = i;
    sort(ord + 1, ord + n + 1, cmp);
    sort(all(cm));
    cm.resize(unique(all(cm)) - cm.begin());
    for(int i = 1; i <= n; i ++) {
	    int I = ord[i];
		///printf("i = %d I = %d X = %d\n", i, I, X[I]);
	    add(lwr(X[I]) + 1, make_pair(Y[I], I));
    }
    for(int i = 1; i <= 2 * n + 2; i ++)
    {
	sort(all(vec[i]));
    }
    for(int i = n; i >= 1; i --)
    {
	merge(all(vec[i << 1]), all(vec[i << 1 | 1]), back_inserter(vec[i]));
    }
    for(int i = 0; i <= 2 * n + 2; i ++)
    {
	seg[i] = set < pair < int , int > > (vec[i].begin(), vec[i].end());
    }
    for (int _ = 1; _ <= n; _++) {
        int i = ord[_];
        if (ret[i]) continue;
        get(lwr(X[i] - 2ll * R[i]) + 1, lwr(X[i] + 2ll * R[i] + 1), Y[i] - 2ll * R[i], Y[i] + 2ll * R[i], i);
    }
    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:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
circle_selection.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |         scanf("%d%d%d", &X[i], &Y[i], &R[i]), base[i] = 1ll * R[i] * R[i] - 1ll * X[i] * X[i] - 1ll * Y[i] * Y[i], cm.push_back(X[i]), ord[i] = i;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 22 ms 42592 KB Output is correct
2 Correct 22 ms 42572 KB Output is correct
3 Correct 22 ms 42508 KB Output is correct
4 Correct 23 ms 42572 KB Output is correct
5 Correct 23 ms 42552 KB Output is correct
6 Correct 23 ms 42564 KB Output is correct
7 Correct 23 ms 42652 KB Output is correct
8 Correct 23 ms 42572 KB Output is correct
9 Correct 24 ms 42636 KB Output is correct
10 Correct 22 ms 42572 KB Output is correct
11 Correct 22 ms 42580 KB Output is correct
12 Correct 23 ms 42660 KB Output is correct
13 Correct 23 ms 42652 KB Output is correct
14 Correct 22 ms 42572 KB Output is correct
15 Correct 23 ms 42584 KB Output is correct
16 Correct 25 ms 43268 KB Output is correct
17 Correct 26 ms 43268 KB Output is correct
18 Correct 27 ms 43324 KB Output is correct
19 Correct 34 ms 46608 KB Output is correct
20 Correct 34 ms 46620 KB Output is correct
21 Correct 38 ms 46576 KB Output is correct
22 Correct 36 ms 46604 KB Output is correct
23 Correct 38 ms 46728 KB Output is correct
24 Correct 35 ms 46636 KB Output is correct
25 Correct 35 ms 46644 KB Output is correct
26 Correct 36 ms 46588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1104 ms 385032 KB Output is correct
2 Correct 1117 ms 384816 KB Output is correct
3 Correct 1095 ms 385032 KB Output is correct
4 Correct 1087 ms 384392 KB Output is correct
5 Correct 1103 ms 383384 KB Output is correct
6 Correct 1191 ms 393408 KB Output is correct
7 Correct 1144 ms 396632 KB Output is correct
8 Correct 1155 ms 396512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 42508 KB Output is correct
2 Correct 451 ms 147688 KB Output is correct
3 Correct 1509 ms 384228 KB Output is correct
4 Correct 1506 ms 384012 KB Output is correct
5 Correct 1535 ms 374440 KB Output is correct
6 Correct 689 ms 212528 KB Output is correct
7 Correct 315 ms 127812 KB Output is correct
8 Correct 72 ms 57900 KB Output is correct
9 Correct 1524 ms 384584 KB Output is correct
10 Correct 1600 ms 384704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1355 ms 385424 KB Output is correct
2 Correct 1189 ms 388780 KB Output is correct
3 Correct 1290 ms 384336 KB Output is correct
4 Correct 1216 ms 384796 KB Output is correct
5 Correct 1198 ms 384444 KB Output is correct
6 Correct 1175 ms 385744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 42592 KB Output is correct
2 Correct 22 ms 42572 KB Output is correct
3 Correct 22 ms 42508 KB Output is correct
4 Correct 23 ms 42572 KB Output is correct
5 Correct 23 ms 42552 KB Output is correct
6 Correct 23 ms 42564 KB Output is correct
7 Correct 23 ms 42652 KB Output is correct
8 Correct 23 ms 42572 KB Output is correct
9 Correct 24 ms 42636 KB Output is correct
10 Correct 22 ms 42572 KB Output is correct
11 Correct 22 ms 42580 KB Output is correct
12 Correct 23 ms 42660 KB Output is correct
13 Correct 23 ms 42652 KB Output is correct
14 Correct 22 ms 42572 KB Output is correct
15 Correct 23 ms 42584 KB Output is correct
16 Correct 25 ms 43268 KB Output is correct
17 Correct 26 ms 43268 KB Output is correct
18 Correct 27 ms 43324 KB Output is correct
19 Correct 34 ms 46608 KB Output is correct
20 Correct 34 ms 46620 KB Output is correct
21 Correct 38 ms 46576 KB Output is correct
22 Correct 36 ms 46604 KB Output is correct
23 Correct 38 ms 46728 KB Output is correct
24 Correct 35 ms 46636 KB Output is correct
25 Correct 35 ms 46644 KB Output is correct
26 Correct 36 ms 46588 KB Output is correct
27 Correct 48 ms 51228 KB Output is correct
28 Correct 48 ms 51268 KB Output is correct
29 Correct 48 ms 51236 KB Output is correct
30 Correct 52 ms 51308 KB Output is correct
31 Correct 51 ms 51384 KB Output is correct
32 Correct 50 ms 51180 KB Output is correct
33 Correct 326 ms 148036 KB Output is correct
34 Correct 340 ms 147832 KB Output is correct
35 Correct 349 ms 147936 KB Output is correct
36 Correct 401 ms 147884 KB Output is correct
37 Correct 399 ms 147636 KB Output is correct
38 Correct 413 ms 147768 KB Output is correct
39 Correct 1101 ms 141480 KB Output is correct
40 Correct 1106 ms 141456 KB Output is correct
41 Correct 1105 ms 141332 KB Output is correct
42 Correct 330 ms 140800 KB Output is correct
43 Correct 343 ms 147608 KB Output is correct
44 Correct 350 ms 147768 KB Output is correct
45 Correct 343 ms 147596 KB Output is correct
46 Correct 347 ms 147764 KB Output is correct
47 Correct 343 ms 147592 KB Output is correct
48 Correct 350 ms 147640 KB Output is correct
49 Correct 346 ms 147700 KB Output is correct
50 Correct 347 ms 147640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 42592 KB Output is correct
2 Correct 22 ms 42572 KB Output is correct
3 Correct 22 ms 42508 KB Output is correct
4 Correct 23 ms 42572 KB Output is correct
5 Correct 23 ms 42552 KB Output is correct
6 Correct 23 ms 42564 KB Output is correct
7 Correct 23 ms 42652 KB Output is correct
8 Correct 23 ms 42572 KB Output is correct
9 Correct 24 ms 42636 KB Output is correct
10 Correct 22 ms 42572 KB Output is correct
11 Correct 22 ms 42580 KB Output is correct
12 Correct 23 ms 42660 KB Output is correct
13 Correct 23 ms 42652 KB Output is correct
14 Correct 22 ms 42572 KB Output is correct
15 Correct 23 ms 42584 KB Output is correct
16 Correct 25 ms 43268 KB Output is correct
17 Correct 26 ms 43268 KB Output is correct
18 Correct 27 ms 43324 KB Output is correct
19 Correct 34 ms 46608 KB Output is correct
20 Correct 34 ms 46620 KB Output is correct
21 Correct 38 ms 46576 KB Output is correct
22 Correct 36 ms 46604 KB Output is correct
23 Correct 38 ms 46728 KB Output is correct
24 Correct 35 ms 46636 KB Output is correct
25 Correct 35 ms 46644 KB Output is correct
26 Correct 36 ms 46588 KB Output is correct
27 Correct 1104 ms 385032 KB Output is correct
28 Correct 1117 ms 384816 KB Output is correct
29 Correct 1095 ms 385032 KB Output is correct
30 Correct 1087 ms 384392 KB Output is correct
31 Correct 1103 ms 383384 KB Output is correct
32 Correct 1191 ms 393408 KB Output is correct
33 Correct 1144 ms 396632 KB Output is correct
34 Correct 1155 ms 396512 KB Output is correct
35 Correct 23 ms 42508 KB Output is correct
36 Correct 451 ms 147688 KB Output is correct
37 Correct 1509 ms 384228 KB Output is correct
38 Correct 1506 ms 384012 KB Output is correct
39 Correct 1535 ms 374440 KB Output is correct
40 Correct 689 ms 212528 KB Output is correct
41 Correct 315 ms 127812 KB Output is correct
42 Correct 72 ms 57900 KB Output is correct
43 Correct 1524 ms 384584 KB Output is correct
44 Correct 1600 ms 384704 KB Output is correct
45 Correct 1355 ms 385424 KB Output is correct
46 Correct 1189 ms 388780 KB Output is correct
47 Correct 1290 ms 384336 KB Output is correct
48 Correct 1216 ms 384796 KB Output is correct
49 Correct 1198 ms 384444 KB Output is correct
50 Correct 1175 ms 385744 KB Output is correct
51 Correct 48 ms 51228 KB Output is correct
52 Correct 48 ms 51268 KB Output is correct
53 Correct 48 ms 51236 KB Output is correct
54 Correct 52 ms 51308 KB Output is correct
55 Correct 51 ms 51384 KB Output is correct
56 Correct 50 ms 51180 KB Output is correct
57 Correct 326 ms 148036 KB Output is correct
58 Correct 340 ms 147832 KB Output is correct
59 Correct 349 ms 147936 KB Output is correct
60 Correct 401 ms 147884 KB Output is correct
61 Correct 399 ms 147636 KB Output is correct
62 Correct 413 ms 147768 KB Output is correct
63 Correct 1101 ms 141480 KB Output is correct
64 Correct 1106 ms 141456 KB Output is correct
65 Correct 1105 ms 141332 KB Output is correct
66 Correct 330 ms 140800 KB Output is correct
67 Correct 343 ms 147608 KB Output is correct
68 Correct 350 ms 147768 KB Output is correct
69 Correct 343 ms 147596 KB Output is correct
70 Correct 347 ms 147764 KB Output is correct
71 Correct 343 ms 147592 KB Output is correct
72 Correct 350 ms 147640 KB Output is correct
73 Correct 346 ms 147700 KB Output is correct
74 Correct 347 ms 147640 KB Output is correct
75 Correct 1158 ms 384372 KB Output is correct
76 Correct 1146 ms 385316 KB Output is correct
77 Correct 1128 ms 390760 KB Output is correct
78 Correct 1108 ms 384976 KB Output is correct
79 Correct 1241 ms 384672 KB Output is correct
80 Correct 1094 ms 384744 KB Output is correct
81 Correct 1480 ms 385260 KB Output is correct
82 Correct 1414 ms 384268 KB Output is correct
83 Correct 1423 ms 384476 KB Output is correct
84 Correct 1587 ms 385960 KB Output is correct
85 Correct 1451 ms 384556 KB Output is correct
86 Correct 1414 ms 383980 KB Output is correct
87 Correct 2130 ms 392132 KB Output is correct
88 Execution timed out 3094 ms 372656 KB Time limit exceeded
89 Halted 0 ms 0 KB -