답안 #966659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966659 2024-04-20T07:50:05 Z Soumya1 원 고르기 (APIO18_circle_selection) C++17
49 / 100
3000 ms 199776 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];
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);
}
bool intersect(int a, int b) {
  return 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]);
}
void update(int a, int b) {
  if (!intersect(a, b)) return;
  if (pos[b] < pos[ans[a]]) 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);
    }
  }
}
vector<int> ck;
void query(int x, int lx, int rx, int p) {
  ck.push_back(x);
  if (lx == rx) return;
  int mx = (lx + rx) >> 1;
  if (p <= mx) query(x << 1, lx, mx, p);
  else query(x << 1 | 1, mx + 1, rx, p);
}
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 (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;
    query(1, 1, N, L);
    query(1, 1, N, R);
    sort(ck.begin(), ck.end());
    ck.erase(unique(ck.begin(), ck.end()), ck.end());
    for (int x : ck) check(x, ii);
    ck.clear();
    if (ans[ii] == ii) {
      update(1, 1, N, 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 52 ms 112980 KB Output is correct
2 Correct 38 ms 112984 KB Output is correct
3 Correct 47 ms 113184 KB Output is correct
4 Correct 38 ms 112976 KB Output is correct
5 Correct 35 ms 113232 KB Output is correct
6 Correct 24 ms 117596 KB Output is correct
7 Correct 25 ms 117592 KB Output is correct
8 Correct 25 ms 117596 KB Output is correct
9 Correct 25 ms 117460 KB Output is correct
10 Correct 27 ms 117596 KB Output is correct
11 Correct 24 ms 117596 KB Output is correct
12 Correct 28 ms 117584 KB Output is correct
13 Correct 25 ms 117596 KB Output is correct
14 Correct 24 ms 117504 KB Output is correct
15 Correct 25 ms 115332 KB Output is correct
16 Correct 25 ms 113496 KB Output is correct
17 Correct 28 ms 113500 KB Output is correct
18 Correct 27 ms 115544 KB Output is correct
19 Correct 38 ms 115800 KB Output is correct
20 Correct 31 ms 115720 KB Output is correct
21 Correct 31 ms 115896 KB Output is correct
22 Correct 32 ms 114264 KB Output is correct
23 Correct 39 ms 115028 KB Output is correct
24 Correct 39 ms 114268 KB Output is correct
25 Correct 31 ms 116056 KB Output is correct
26 Correct 31 ms 114272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 874 ms 131092 KB Output is correct
2 Correct 942 ms 132480 KB Output is correct
3 Correct 898 ms 131016 KB Output is correct
4 Correct 874 ms 132624 KB Output is correct
5 Correct 801 ms 131168 KB Output is correct
6 Correct 825 ms 141368 KB Output is correct
7 Correct 820 ms 131780 KB Output is correct
8 Correct 795 ms 134660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 117596 KB Output is correct
2 Correct 563 ms 144988 KB Output is correct
3 Correct 2103 ms 198752 KB Output is correct
4 Correct 2183 ms 199776 KB Output is correct
5 Execution timed out 3075 ms 191960 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1460 ms 190964 KB Output is correct
2 Correct 725 ms 154572 KB Output is correct
3 Execution timed out 3032 ms 139132 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 112980 KB Output is correct
2 Correct 38 ms 112984 KB Output is correct
3 Correct 47 ms 113184 KB Output is correct
4 Correct 38 ms 112976 KB Output is correct
5 Correct 35 ms 113232 KB Output is correct
6 Correct 24 ms 117596 KB Output is correct
7 Correct 25 ms 117592 KB Output is correct
8 Correct 25 ms 117596 KB Output is correct
9 Correct 25 ms 117460 KB Output is correct
10 Correct 27 ms 117596 KB Output is correct
11 Correct 24 ms 117596 KB Output is correct
12 Correct 28 ms 117584 KB Output is correct
13 Correct 25 ms 117596 KB Output is correct
14 Correct 24 ms 117504 KB Output is correct
15 Correct 25 ms 115332 KB Output is correct
16 Correct 25 ms 113496 KB Output is correct
17 Correct 28 ms 113500 KB Output is correct
18 Correct 27 ms 115544 KB Output is correct
19 Correct 38 ms 115800 KB Output is correct
20 Correct 31 ms 115720 KB Output is correct
21 Correct 31 ms 115896 KB Output is correct
22 Correct 32 ms 114264 KB Output is correct
23 Correct 39 ms 115028 KB Output is correct
24 Correct 39 ms 114268 KB Output is correct
25 Correct 31 ms 116056 KB Output is correct
26 Correct 31 ms 114272 KB Output is correct
27 Correct 41 ms 118136 KB Output is correct
28 Correct 39 ms 117960 KB Output is correct
29 Correct 39 ms 118096 KB Output is correct
30 Correct 56 ms 119772 KB Output is correct
31 Correct 44 ms 119108 KB Output is correct
32 Correct 45 ms 119120 KB Output is correct
33 Correct 207 ms 122824 KB Output is correct
34 Correct 245 ms 122612 KB Output is correct
35 Correct 278 ms 122628 KB Output is correct
36 Correct 321 ms 135376 KB Output is correct
37 Correct 328 ms 135904 KB Output is correct
38 Correct 315 ms 137928 KB Output is correct
39 Correct 991 ms 123808 KB Output is correct
40 Correct 983 ms 123972 KB Output is correct
41 Correct 980 ms 123784 KB Output is correct
42 Correct 725 ms 124408 KB Output is correct
43 Correct 247 ms 129548 KB Output is correct
44 Correct 291 ms 129684 KB Output is correct
45 Correct 229 ms 129536 KB Output is correct
46 Correct 239 ms 129484 KB Output is correct
47 Correct 247 ms 129476 KB Output is correct
48 Correct 260 ms 129512 KB Output is correct
49 Correct 242 ms 129448 KB Output is correct
50 Correct 243 ms 129612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 112980 KB Output is correct
2 Correct 38 ms 112984 KB Output is correct
3 Correct 47 ms 113184 KB Output is correct
4 Correct 38 ms 112976 KB Output is correct
5 Correct 35 ms 113232 KB Output is correct
6 Correct 24 ms 117596 KB Output is correct
7 Correct 25 ms 117592 KB Output is correct
8 Correct 25 ms 117596 KB Output is correct
9 Correct 25 ms 117460 KB Output is correct
10 Correct 27 ms 117596 KB Output is correct
11 Correct 24 ms 117596 KB Output is correct
12 Correct 28 ms 117584 KB Output is correct
13 Correct 25 ms 117596 KB Output is correct
14 Correct 24 ms 117504 KB Output is correct
15 Correct 25 ms 115332 KB Output is correct
16 Correct 25 ms 113496 KB Output is correct
17 Correct 28 ms 113500 KB Output is correct
18 Correct 27 ms 115544 KB Output is correct
19 Correct 38 ms 115800 KB Output is correct
20 Correct 31 ms 115720 KB Output is correct
21 Correct 31 ms 115896 KB Output is correct
22 Correct 32 ms 114264 KB Output is correct
23 Correct 39 ms 115028 KB Output is correct
24 Correct 39 ms 114268 KB Output is correct
25 Correct 31 ms 116056 KB Output is correct
26 Correct 31 ms 114272 KB Output is correct
27 Correct 874 ms 131092 KB Output is correct
28 Correct 942 ms 132480 KB Output is correct
29 Correct 898 ms 131016 KB Output is correct
30 Correct 874 ms 132624 KB Output is correct
31 Correct 801 ms 131168 KB Output is correct
32 Correct 825 ms 141368 KB Output is correct
33 Correct 820 ms 131780 KB Output is correct
34 Correct 795 ms 134660 KB Output is correct
35 Correct 25 ms 117596 KB Output is correct
36 Correct 563 ms 144988 KB Output is correct
37 Correct 2103 ms 198752 KB Output is correct
38 Correct 2183 ms 199776 KB Output is correct
39 Execution timed out 3075 ms 191960 KB Time limit exceeded
40 Halted 0 ms 0 KB -