Submission #49847

# Submission time Handle Problem Language Result Execution time Memory
49847 2018-06-03T19:28:14 Z zemen Circle selection (APIO18_circle_selection) C++17
87 / 100
3000 ms 308992 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

#define int ll

struct Circle {
  int x, y, r, id, ord;

  static ll sqr(ll x) {
    return x * x;
  }

  bool intersects(const Circle& c) const {
    return sqr(c.x - x) + sqr(c.y - y) <= sqr(r + c.r);
  }
};
istream& operator>>(istream& in, Circle& c) {
  return in >> c.x >> c.y >> c.r;
}

const ll infl = 1e18 + 7;

struct Bbox {
  ll xl, xr, yl, yr;

  Bbox() : xl(infl), xr(-infl), yl(infl), yr(-infl) {
  }

  void add(const Circle& c) {
    xl = min<ll>(xl, c.x - c.r);
    xr = max<ll>(xr, c.x + c.r);
    yl = min<ll>(yl, c.y - c.r);
    yr = max<ll>(yr, c.y + c.r);
  }

  bool intersects(const Circle& c) const {
    if (empty()) {
      return false;
    }
    if (c.x - c.r > xr || c.x + c.r < xl) {
      return false;
    }
    if (c.y - c.r > yr || c.y + c.r < yl) {
      return false;
    }
    return true;
  }

  bool empty() const {
    return xl == infl;
  }
};

const int base = 1 << 19;
vector<Circle> t[base * 2];
Bbox box[base * 2];
int endv[base];

bool cmpx(const Circle& a, const Circle& b) {
  return a.x < b.x || (a.x == b.x && a.y < b.y);
}

bool cmpy(const Circle& a, const Circle& b) {
  return a.y < b.y || (a.y == b.y && a.x < b.x);
}

bool cmpr(const Circle& a, const Circle& b) {
  return a.r > b.r || (a.r == b.r && a.id < b.id);
}

void build(int v, bool byx) {
  assert(!t[v].empty());
  sort(t[v].begin(), t[v].end(), byx ? cmpx : cmpy);
  if (t[v].size() == 1) {
    endv[t[v][0].id] = v;
    return;
  }
  int n = (int) t[v].size();
  t[v * 2].insert(t[v * 2].end(), t[v].begin(), t[v].begin() + n / 2);
  t[v * 2 + 1].insert(t[v * 2 + 1].end(), t[v].begin() + n / 2, t[v].end());
  build(v * 2, !byx);
  build(v * 2 + 1, !byx);
}

const int inf = 1e9;
int lookup(const Circle& c, int v = 1) {
  if (box[v].empty()) {
    return inf;
  }
  if (!box[v].intersects(c)) {
    return inf;
  }
  if (t[v].size() == 1) {
    if (t[v][0].intersects(c)) {
      return t[v][0].ord;
    } else {
      return inf;
    }
  }
  return min(lookup(c, v * 2), lookup(c, v * 2 + 1));
}

void turn_on(int id) {
  int v = endv[id];
  const Circle& c = t[v][0];
  while (v >= 1) {
    box[v].add(c);
    v /= 2;
  }
}

signed main() {
#ifdef LOCAL
  assert(freopen("b.in", "r", stdin));
#endif
  int n;
  cin >> n;
  vector<Circle> cs;
  for (int i = 0; i < n; ++i) {
    Circle c;
    cin >> c;
    c.id = i;
    cs.push_back(c);
  }
  sort(cs.begin(), cs.end(), cmpr);
  for (int i = 0; i < (int) cs.size(); ++i) {
    cs[i].ord = i;
  }
  t[1] = cs;
  build(1, true);

  vector<int> res(n);
  for (auto& c : cs) {
    int id = lookup(c);
    if (id == inf) {
      turn_on(c.id);
      id = c.id;
    } else {
      id = cs[id].id;
    }
    res[c.id] = id;
  }
  for (int x : res) {
    cout << x + 1 << ' ';
  }
  cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 49 ms 57720 KB Output is correct
2 Correct 58 ms 57832 KB Output is correct
3 Correct 51 ms 57884 KB Output is correct
4 Correct 47 ms 57944 KB Output is correct
5 Correct 46 ms 57944 KB Output is correct
6 Correct 48 ms 57992 KB Output is correct
7 Correct 45 ms 57992 KB Output is correct
8 Correct 55 ms 57992 KB Output is correct
9 Correct 49 ms 58120 KB Output is correct
10 Correct 51 ms 58120 KB Output is correct
11 Correct 51 ms 58120 KB Output is correct
12 Correct 46 ms 58120 KB Output is correct
13 Correct 46 ms 58120 KB Output is correct
14 Correct 46 ms 58120 KB Output is correct
15 Correct 46 ms 58120 KB Output is correct
16 Correct 54 ms 58508 KB Output is correct
17 Correct 49 ms 58596 KB Output is correct
18 Correct 50 ms 58696 KB Output is correct
19 Correct 87 ms 61024 KB Output is correct
20 Correct 67 ms 61096 KB Output is correct
21 Correct 68 ms 61112 KB Output is correct
22 Correct 64 ms 61128 KB Output is correct
23 Correct 70 ms 61140 KB Output is correct
24 Correct 66 ms 61140 KB Output is correct
25 Correct 63 ms 61140 KB Output is correct
26 Correct 66 ms 61140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1236 ms 308824 KB Output is correct
2 Correct 1260 ms 308824 KB Output is correct
3 Correct 1276 ms 308824 KB Output is correct
4 Correct 1253 ms 308856 KB Output is correct
5 Correct 1458 ms 308856 KB Output is correct
6 Correct 1441 ms 308856 KB Output is correct
7 Correct 1253 ms 308856 KB Output is correct
8 Correct 1415 ms 308856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 308856 KB Output is correct
2 Correct 549 ms 308856 KB Output is correct
3 Correct 1887 ms 308856 KB Output is correct
4 Correct 1847 ms 308992 KB Output is correct
5 Correct 1875 ms 308992 KB Output is correct
6 Correct 971 ms 308992 KB Output is correct
7 Correct 509 ms 308992 KB Output is correct
8 Correct 120 ms 308992 KB Output is correct
9 Correct 1761 ms 308992 KB Output is correct
10 Correct 1650 ms 308992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1581 ms 308992 KB Output is correct
2 Correct 1645 ms 308992 KB Output is correct
3 Correct 2184 ms 308992 KB Output is correct
4 Correct 1773 ms 308992 KB Output is correct
5 Correct 1875 ms 308992 KB Output is correct
6 Correct 1808 ms 308992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 57720 KB Output is correct
2 Correct 58 ms 57832 KB Output is correct
3 Correct 51 ms 57884 KB Output is correct
4 Correct 47 ms 57944 KB Output is correct
5 Correct 46 ms 57944 KB Output is correct
6 Correct 48 ms 57992 KB Output is correct
7 Correct 45 ms 57992 KB Output is correct
8 Correct 55 ms 57992 KB Output is correct
9 Correct 49 ms 58120 KB Output is correct
10 Correct 51 ms 58120 KB Output is correct
11 Correct 51 ms 58120 KB Output is correct
12 Correct 46 ms 58120 KB Output is correct
13 Correct 46 ms 58120 KB Output is correct
14 Correct 46 ms 58120 KB Output is correct
15 Correct 46 ms 58120 KB Output is correct
16 Correct 54 ms 58508 KB Output is correct
17 Correct 49 ms 58596 KB Output is correct
18 Correct 50 ms 58696 KB Output is correct
19 Correct 87 ms 61024 KB Output is correct
20 Correct 67 ms 61096 KB Output is correct
21 Correct 68 ms 61112 KB Output is correct
22 Correct 64 ms 61128 KB Output is correct
23 Correct 70 ms 61140 KB Output is correct
24 Correct 66 ms 61140 KB Output is correct
25 Correct 63 ms 61140 KB Output is correct
26 Correct 66 ms 61140 KB Output is correct
27 Correct 77 ms 308992 KB Output is correct
28 Correct 81 ms 308992 KB Output is correct
29 Correct 95 ms 308992 KB Output is correct
30 Correct 91 ms 308992 KB Output is correct
31 Correct 104 ms 308992 KB Output is correct
32 Correct 85 ms 308992 KB Output is correct
33 Correct 479 ms 308992 KB Output is correct
34 Correct 575 ms 308992 KB Output is correct
35 Correct 508 ms 308992 KB Output is correct
36 Correct 522 ms 308992 KB Output is correct
37 Correct 513 ms 308992 KB Output is correct
38 Correct 546 ms 308992 KB Output is correct
39 Correct 578 ms 308992 KB Output is correct
40 Correct 600 ms 308992 KB Output is correct
41 Correct 593 ms 308992 KB Output is correct
42 Correct 493 ms 308992 KB Output is correct
43 Correct 441 ms 308992 KB Output is correct
44 Correct 468 ms 308992 KB Output is correct
45 Correct 470 ms 308992 KB Output is correct
46 Correct 545 ms 308992 KB Output is correct
47 Correct 520 ms 308992 KB Output is correct
48 Correct 518 ms 308992 KB Output is correct
49 Correct 487 ms 308992 KB Output is correct
50 Correct 498 ms 308992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 57720 KB Output is correct
2 Correct 58 ms 57832 KB Output is correct
3 Correct 51 ms 57884 KB Output is correct
4 Correct 47 ms 57944 KB Output is correct
5 Correct 46 ms 57944 KB Output is correct
6 Correct 48 ms 57992 KB Output is correct
7 Correct 45 ms 57992 KB Output is correct
8 Correct 55 ms 57992 KB Output is correct
9 Correct 49 ms 58120 KB Output is correct
10 Correct 51 ms 58120 KB Output is correct
11 Correct 51 ms 58120 KB Output is correct
12 Correct 46 ms 58120 KB Output is correct
13 Correct 46 ms 58120 KB Output is correct
14 Correct 46 ms 58120 KB Output is correct
15 Correct 46 ms 58120 KB Output is correct
16 Correct 54 ms 58508 KB Output is correct
17 Correct 49 ms 58596 KB Output is correct
18 Correct 50 ms 58696 KB Output is correct
19 Correct 87 ms 61024 KB Output is correct
20 Correct 67 ms 61096 KB Output is correct
21 Correct 68 ms 61112 KB Output is correct
22 Correct 64 ms 61128 KB Output is correct
23 Correct 70 ms 61140 KB Output is correct
24 Correct 66 ms 61140 KB Output is correct
25 Correct 63 ms 61140 KB Output is correct
26 Correct 66 ms 61140 KB Output is correct
27 Correct 1236 ms 308824 KB Output is correct
28 Correct 1260 ms 308824 KB Output is correct
29 Correct 1276 ms 308824 KB Output is correct
30 Correct 1253 ms 308856 KB Output is correct
31 Correct 1458 ms 308856 KB Output is correct
32 Correct 1441 ms 308856 KB Output is correct
33 Correct 1253 ms 308856 KB Output is correct
34 Correct 1415 ms 308856 KB Output is correct
35 Correct 51 ms 308856 KB Output is correct
36 Correct 549 ms 308856 KB Output is correct
37 Correct 1887 ms 308856 KB Output is correct
38 Correct 1847 ms 308992 KB Output is correct
39 Correct 1875 ms 308992 KB Output is correct
40 Correct 971 ms 308992 KB Output is correct
41 Correct 509 ms 308992 KB Output is correct
42 Correct 120 ms 308992 KB Output is correct
43 Correct 1761 ms 308992 KB Output is correct
44 Correct 1650 ms 308992 KB Output is correct
45 Correct 1581 ms 308992 KB Output is correct
46 Correct 1645 ms 308992 KB Output is correct
47 Correct 2184 ms 308992 KB Output is correct
48 Correct 1773 ms 308992 KB Output is correct
49 Correct 1875 ms 308992 KB Output is correct
50 Correct 1808 ms 308992 KB Output is correct
51 Correct 77 ms 308992 KB Output is correct
52 Correct 81 ms 308992 KB Output is correct
53 Correct 95 ms 308992 KB Output is correct
54 Correct 91 ms 308992 KB Output is correct
55 Correct 104 ms 308992 KB Output is correct
56 Correct 85 ms 308992 KB Output is correct
57 Correct 479 ms 308992 KB Output is correct
58 Correct 575 ms 308992 KB Output is correct
59 Correct 508 ms 308992 KB Output is correct
60 Correct 522 ms 308992 KB Output is correct
61 Correct 513 ms 308992 KB Output is correct
62 Correct 546 ms 308992 KB Output is correct
63 Correct 578 ms 308992 KB Output is correct
64 Correct 600 ms 308992 KB Output is correct
65 Correct 593 ms 308992 KB Output is correct
66 Correct 493 ms 308992 KB Output is correct
67 Correct 441 ms 308992 KB Output is correct
68 Correct 468 ms 308992 KB Output is correct
69 Correct 470 ms 308992 KB Output is correct
70 Correct 545 ms 308992 KB Output is correct
71 Correct 520 ms 308992 KB Output is correct
72 Correct 518 ms 308992 KB Output is correct
73 Correct 487 ms 308992 KB Output is correct
74 Correct 498 ms 308992 KB Output is correct
75 Correct 1492 ms 308992 KB Output is correct
76 Correct 1579 ms 308992 KB Output is correct
77 Correct 1604 ms 308992 KB Output is correct
78 Correct 1472 ms 308992 KB Output is correct
79 Correct 1510 ms 308992 KB Output is correct
80 Correct 1471 ms 308992 KB Output is correct
81 Correct 1886 ms 308992 KB Output is correct
82 Correct 1857 ms 308992 KB Output is correct
83 Correct 1826 ms 308992 KB Output is correct
84 Correct 1893 ms 308992 KB Output is correct
85 Correct 1821 ms 308992 KB Output is correct
86 Correct 1820 ms 308992 KB Output is correct
87 Correct 1800 ms 308992 KB Output is correct
88 Correct 2150 ms 308992 KB Output is correct
89 Correct 2041 ms 308992 KB Output is correct
90 Correct 2087 ms 308992 KB Output is correct
91 Correct 2212 ms 308992 KB Output is correct
92 Correct 2112 ms 308992 KB Output is correct
93 Correct 2476 ms 308992 KB Output is correct
94 Execution timed out 3070 ms 308992 KB Time limit exceeded
95 Halted 0 ms 0 KB -