답안 #966674

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966674 2024-04-20T08:03:10 Z Soumya1 원 고르기 (APIO18_circle_selection) C++17
72 / 100
3000 ms 198372 KB
#include <bits/stdc++.h>
using namespace std;
const int mxN = 3e5 + 5;
int x[mxN], y[mxN], r[mxN], pos[mxN], ans[mxN];
set<pair<int, int>> st[2 * 4 * mxN];
int base;
void upd(int p, int q, int i) {
  p += base; q += base;
  p--; q--;
  while (p <= q) {
    if (p & 1) st[p++].insert({y[i], i});
    if (~q & 1) st[q--].insert({y[i], i});
    p >>= 1; q >>= 1;
  }
}
void update(int a, int b) {
  if (pos[b] < pos[ans[a]] && 1LL * (x[a] - x[b]) * (x[a] - x[b]) + 1LL * (y[a] - y[b]) * (y[a] - y[b]) <= 1LL * (r[a] + r[b]) * (r[a] + r[b]))
    ans[a] = b;
}
void check(int x, int i) {
  auto it = lower_bound(st[x].begin(), st[x].end(), pair<int, int> {y[i], -2e9});
  if (it != st[x].end()) {
    update(i, (*it).second);
    it++;
    if (it != st[x].end()) {
      update(i, (*it).second);
    }
  }
  it = lower_bound(st[x].begin(), st[x].end(), pair<int, int> {y[i], -2e9});
  if (it != st[x].begin()) {
    it--;
    update(i, (*it).second);
    if (it != st[x].begin()) {
      it--;
      update(i, (*it).second);
    }
  }
}
void get(int p, int i) {
  p += base; p--;
  while (p >= 1) {
    check(p, i);
    p >>= 1;
  }
}
// void update(int x, int lx, int rx, int l, int r, int i) {
//   if (l > rx || lx > r) return;
//   if (l <= lx && r >= rx) {
//     st[x].insert({y[i], i});
//     return;
//   }
//   int mx = (lx + rx) >> 1;
//   update(x << 1, lx, mx, l, r, i);
//   update(x << 1 | 1, mx + 1, rx, l, r, i);
// }
// void query(int x, int lx, int rx, int p, int i) {
//   check(x, i);
//   if (lx == rx) return;
//   int mx = (lx + rx) >> 1;
//   if (p <= mx) query(x << 1, lx, mx, p, i);
//   else query(x << 1 | 1, mx + 1, rx, p, i);
// }
void testCase() {
  int n;
  cin >> n;
  vector<int> all;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> r[i];
    all.push_back(x[i] - r[i]);
    all.push_back(x[i] + r[i]); 
  }
  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int i, int j) {
    if (r[i] != r[j]) return r[i] > r[j];
    return i < j;
  });
  for (int i = 0; i < n; i++) {
    pos[ord[i]] = i;
  }
  sort(all.begin(), all.end());
  all.erase(unique(all.begin(), all.end()), all.end());
  int N = all.size();
  for (base = 1; base < N; base <<= 1);
  for (int i = 0; i < n; i++) ans[i] = i;
  for (int i = 0; i < n; i++) {
    int ii = ord[i];
    int L = lower_bound(all.begin(), all.end(), x[ii] - r[ii]) - all.begin() + 1;
    int R = lower_bound(all.begin(), all.end(), x[ii] + r[ii]) - all.begin() + 1;
    get(L, ii);
    get(R, ii);
    if (ans[ii] == ii) {
      upd(L, R, ii);
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i] + 1 << " ";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 113184 KB Output is correct
2 Correct 39 ms 113184 KB Output is correct
3 Correct 37 ms 113020 KB Output is correct
4 Correct 46 ms 112976 KB Output is correct
5 Correct 37 ms 113152 KB Output is correct
6 Correct 39 ms 112988 KB Output is correct
7 Correct 42 ms 112976 KB Output is correct
8 Correct 41 ms 113152 KB Output is correct
9 Correct 41 ms 112988 KB Output is correct
10 Correct 38 ms 112984 KB Output is correct
11 Correct 43 ms 112972 KB Output is correct
12 Correct 40 ms 112996 KB Output is correct
13 Correct 39 ms 117244 KB Output is correct
14 Correct 48 ms 113212 KB Output is correct
15 Correct 42 ms 113196 KB Output is correct
16 Correct 43 ms 113236 KB Output is correct
17 Correct 40 ms 113260 KB Output is correct
18 Correct 39 ms 113244 KB Output is correct
19 Correct 42 ms 113496 KB Output is correct
20 Correct 46 ms 113564 KB Output is correct
21 Correct 58 ms 113488 KB Output is correct
22 Correct 51 ms 114000 KB Output is correct
23 Correct 58 ms 118740 KB Output is correct
24 Correct 58 ms 113748 KB Output is correct
25 Correct 54 ms 113660 KB Output is correct
26 Correct 46 ms 113744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 683 ms 131356 KB Output is correct
2 Correct 805 ms 131288 KB Output is correct
3 Correct 734 ms 131000 KB Output is correct
4 Correct 816 ms 131356 KB Output is correct
5 Correct 614 ms 130276 KB Output is correct
6 Correct 647 ms 139968 KB Output is correct
7 Correct 666 ms 132032 KB Output is correct
8 Correct 636 ms 134032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 112988 KB Output is correct
2 Correct 498 ms 141952 KB Output is correct
3 Correct 1929 ms 198372 KB Output is correct
4 Correct 1900 ms 197944 KB Output is correct
5 Execution timed out 3022 ms 190504 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1230 ms 189600 KB Output is correct
2 Correct 580 ms 152760 KB Output is correct
3 Correct 2986 ms 139956 KB Output is correct
4 Correct 711 ms 157032 KB Output is correct
5 Correct 554 ms 154560 KB Output is correct
6 Correct 2288 ms 134088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 113184 KB Output is correct
2 Correct 39 ms 113184 KB Output is correct
3 Correct 37 ms 113020 KB Output is correct
4 Correct 46 ms 112976 KB Output is correct
5 Correct 37 ms 113152 KB Output is correct
6 Correct 39 ms 112988 KB Output is correct
7 Correct 42 ms 112976 KB Output is correct
8 Correct 41 ms 113152 KB Output is correct
9 Correct 41 ms 112988 KB Output is correct
10 Correct 38 ms 112984 KB Output is correct
11 Correct 43 ms 112972 KB Output is correct
12 Correct 40 ms 112996 KB Output is correct
13 Correct 39 ms 117244 KB Output is correct
14 Correct 48 ms 113212 KB Output is correct
15 Correct 42 ms 113196 KB Output is correct
16 Correct 43 ms 113236 KB Output is correct
17 Correct 40 ms 113260 KB Output is correct
18 Correct 39 ms 113244 KB Output is correct
19 Correct 42 ms 113496 KB Output is correct
20 Correct 46 ms 113564 KB Output is correct
21 Correct 58 ms 113488 KB Output is correct
22 Correct 51 ms 114000 KB Output is correct
23 Correct 58 ms 118740 KB Output is correct
24 Correct 58 ms 113748 KB Output is correct
25 Correct 54 ms 113660 KB Output is correct
26 Correct 46 ms 113744 KB Output is correct
27 Correct 41 ms 118108 KB Output is correct
28 Correct 36 ms 114192 KB Output is correct
29 Correct 43 ms 114188 KB Output is correct
30 Correct 47 ms 115792 KB Output is correct
31 Correct 38 ms 117072 KB Output is correct
32 Correct 42 ms 115112 KB Output is correct
33 Correct 160 ms 121232 KB Output is correct
34 Correct 209 ms 122760 KB Output is correct
35 Correct 214 ms 122624 KB Output is correct
36 Correct 239 ms 135008 KB Output is correct
37 Correct 313 ms 135468 KB Output is correct
38 Correct 275 ms 137676 KB Output is correct
39 Correct 1096 ms 123720 KB Output is correct
40 Correct 1093 ms 123924 KB Output is correct
41 Correct 1065 ms 123624 KB Output is correct
42 Correct 706 ms 124544 KB Output is correct
43 Correct 184 ms 129300 KB Output is correct
44 Correct 180 ms 128740 KB Output is correct
45 Correct 176 ms 129184 KB Output is correct
46 Correct 236 ms 128968 KB Output is correct
47 Correct 183 ms 128260 KB Output is correct
48 Correct 186 ms 128968 KB Output is correct
49 Correct 186 ms 127688 KB Output is correct
50 Correct 165 ms 128460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 113184 KB Output is correct
2 Correct 39 ms 113184 KB Output is correct
3 Correct 37 ms 113020 KB Output is correct
4 Correct 46 ms 112976 KB Output is correct
5 Correct 37 ms 113152 KB Output is correct
6 Correct 39 ms 112988 KB Output is correct
7 Correct 42 ms 112976 KB Output is correct
8 Correct 41 ms 113152 KB Output is correct
9 Correct 41 ms 112988 KB Output is correct
10 Correct 38 ms 112984 KB Output is correct
11 Correct 43 ms 112972 KB Output is correct
12 Correct 40 ms 112996 KB Output is correct
13 Correct 39 ms 117244 KB Output is correct
14 Correct 48 ms 113212 KB Output is correct
15 Correct 42 ms 113196 KB Output is correct
16 Correct 43 ms 113236 KB Output is correct
17 Correct 40 ms 113260 KB Output is correct
18 Correct 39 ms 113244 KB Output is correct
19 Correct 42 ms 113496 KB Output is correct
20 Correct 46 ms 113564 KB Output is correct
21 Correct 58 ms 113488 KB Output is correct
22 Correct 51 ms 114000 KB Output is correct
23 Correct 58 ms 118740 KB Output is correct
24 Correct 58 ms 113748 KB Output is correct
25 Correct 54 ms 113660 KB Output is correct
26 Correct 46 ms 113744 KB Output is correct
27 Correct 683 ms 131356 KB Output is correct
28 Correct 805 ms 131288 KB Output is correct
29 Correct 734 ms 131000 KB Output is correct
30 Correct 816 ms 131356 KB Output is correct
31 Correct 614 ms 130276 KB Output is correct
32 Correct 647 ms 139968 KB Output is correct
33 Correct 666 ms 132032 KB Output is correct
34 Correct 636 ms 134032 KB Output is correct
35 Correct 37 ms 112988 KB Output is correct
36 Correct 498 ms 141952 KB Output is correct
37 Correct 1929 ms 198372 KB Output is correct
38 Correct 1900 ms 197944 KB Output is correct
39 Execution timed out 3022 ms 190504 KB Time limit exceeded
40 Halted 0 ms 0 KB -