답안 #968056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968056 2024-04-23T07:27:41 Z socpite 원 고르기 (APIO18_circle_selection) C++14
19 / 100
3000 ms 41008 KB
#include<bits/stdc++.h>
using namespace std;

const int maxn = 3e5+5;
const int INF = 1e9+5;

pair<int, int> pt[maxn];

bool cmpx(int a, int b){
    return pt[a].first < pt[b].first; 
}

bool cmpy(int a, int b){
    return pt[a].second < pt[b].second;
}

int n;
int st[4*maxn], Lx[4*maxn], Rx[4*maxn], Ly[4*maxn], Ry[4*maxn];
int pid[4*maxn];
int pos[maxn];
int removed[maxn];
int R[maxn];

bool cmpr(int a, int b){
    return R[a] != R[b] ? R[a] > R[b] : a < b; 
}

bool check(int a, int b){
    return 1LL*(pt[a].first - pt[b].first)*(pt[a].first - pt[b].first) + 1LL*(pt[a].second - pt[b].second)*(pt[a].second - pt[b].second) - 1LL*(R[a] + R[b])*(R[a] + R[b])  <= 0;
}

void build(vector<int> vec, int dep, int id){
    Lx[id] = Ly[id] = INF;
    if(vec.empty())return;
    sort(vec.begin(), vec.end(), dep&1 ? cmpx : cmpy);
    int mid = vec.size()/2;
    pid[id] = vec[mid];
    pos[vec[mid]] = id;
    vector<int> v1, v2;
    for(int i = 0; i < vec.size(); i++){
        if(i < mid)v1.push_back(vec[i]);
        if(i > mid)v2.push_back(vec[i]);
    }
    for(auto v: vec){
        st[id] = max(st[id], R[v]);
        Lx[id] = min(Lx[id], pt[v].first);
        Ly[id] = min(Ly[id], pt[v].second);
        Rx[id] = max(Rx[id], pt[v].first);
        Ry[id] = max(Ry[id], pt[v].second);
    }
    build(v1, dep^1, id<<1);
    build(v2, dep^1, id<<1|1);
}

void recalc(int id){
    st[id] = max(st[id<<1], st[id<<1|1]);
    Lx[id] = min(Lx[id<<1], Lx[id<<1|1]);
    Ly[id] = min(Ly[id<<1], Ly[id<<1|1]);
    Rx[id] = max(Rx[id<<1], Rx[id<<1|1]);
    Ry[id] = max(Ry[id<<1], Ry[id<<1|1]);
    if(pid[id]){
        st[id] = max(st[id], R[pid[id]]);
        Lx[id] = min(Lx[id], pt[pid[id]].first);
        Ly[id] = min(Ly[id], pt[pid[id]].second);
        Rx[id] = max(Rx[id], pt[pid[id]].first);
        Ry[id] = max(Ry[id], pt[pid[id]].second);
    }
}

void remove(int x){
    int id = pos[x];
    pid[id] = 0;
    while(id){
        recalc(id);
        id >>= 1;
    }
}

void search(int x, int dep, int id){
    if(pid[id]){
        if(check(x, pid[id])){
            removed[pid[id]] = x;
            remove(pid[id]);
        }
    }
    if(st[id<<1] && (dep&1 ? (pt[x].first < Rx[id<<1] || pt[x].first - Rx[id<<1] <= R[x] + st[id<<1]) :
                            (pt[x].second < Ry[id<<1] || pt[x].second - Ry[id<<1] <= R[x] + st[id<<1])))search(x, dep^1, id<<1);
    if(st[id<<1|1] && (dep&1 ? (pt[x].first > Lx[id<<1|1] || Lx[id<<1|1] - pt[x].first <= R[x] + st[id<<1|1]) :
                            (pt[x].second > Ly[id<<1|1] || Ly[id<<1|1] - pt[x].second <= R[x] + st[id<<1|1])))search(x, dep^1, id<<1|1);
}

vector<int> bad;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    vector<int> vec(n);
    iota(vec.begin(), vec.end(), 1);
    for(int i = 1; i <= n; i++){
        cin >> pt[i].first >> pt[i].second >> R[i];
    }
    build(vec, 0, 1);
    sort(vec.begin(), vec.end(), cmpr);
    for(auto v: vec){
        if(removed[v])continue;
        search(v, 0, 1);
    }
    for(int i = 1; i <= n; i++)cout << removed[i] << " ";
}

Compilation message

circle_selection.cpp: In function 'void build(std::vector<int>, int, int)':
circle_selection.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 0; i < vec.size(); i++){
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8652 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8792 KB Output is correct
9 Correct 1 ms 8656 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 7 ms 9052 KB Output is correct
20 Correct 7 ms 9052 KB Output is correct
21 Correct 9 ms 9052 KB Output is correct
22 Correct 8 ms 9052 KB Output is correct
23 Correct 11 ms 9052 KB Output is correct
24 Correct 38 ms 9088 KB Output is correct
25 Correct 8 ms 9048 KB Output is correct
26 Correct 8 ms 9052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 399 ms 39612 KB Output is correct
2 Correct 392 ms 39428 KB Output is correct
3 Correct 399 ms 39544 KB Output is correct
4 Correct 387 ms 39612 KB Output is correct
5 Correct 441 ms 37380 KB Output is correct
6 Correct 1653 ms 37644 KB Output is correct
7 Correct 520 ms 37632 KB Output is correct
8 Correct 716 ms 37556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1391 ms 19296 KB Output is correct
3 Execution timed out 3026 ms 41008 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3033 ms 40764 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8652 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8792 KB Output is correct
9 Correct 1 ms 8656 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 7 ms 9052 KB Output is correct
20 Correct 7 ms 9052 KB Output is correct
21 Correct 9 ms 9052 KB Output is correct
22 Correct 8 ms 9052 KB Output is correct
23 Correct 11 ms 9052 KB Output is correct
24 Correct 38 ms 9088 KB Output is correct
25 Correct 8 ms 9048 KB Output is correct
26 Correct 8 ms 9052 KB Output is correct
27 Correct 16 ms 9308 KB Output is correct
28 Correct 13 ms 9308 KB Output is correct
29 Correct 13 ms 9372 KB Output is correct
30 Correct 23 ms 9304 KB Output is correct
31 Correct 15 ms 9308 KB Output is correct
32 Correct 25 ms 9308 KB Output is correct
33 Correct 174 ms 19644 KB Output is correct
34 Correct 177 ms 19628 KB Output is correct
35 Correct 169 ms 19304 KB Output is correct
36 Correct 211 ms 18904 KB Output is correct
37 Correct 586 ms 19084 KB Output is correct
38 Correct 578 ms 19060 KB Output is correct
39 Correct 479 ms 17648 KB Output is correct
40 Correct 459 ms 17624 KB Output is correct
41 Correct 466 ms 17740 KB Output is correct
42 Correct 158 ms 18132 KB Output is correct
43 Execution timed out 3054 ms 19344 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8652 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8792 KB Output is correct
9 Correct 1 ms 8656 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 7 ms 9052 KB Output is correct
20 Correct 7 ms 9052 KB Output is correct
21 Correct 9 ms 9052 KB Output is correct
22 Correct 8 ms 9052 KB Output is correct
23 Correct 11 ms 9052 KB Output is correct
24 Correct 38 ms 9088 KB Output is correct
25 Correct 8 ms 9048 KB Output is correct
26 Correct 8 ms 9052 KB Output is correct
27 Correct 399 ms 39612 KB Output is correct
28 Correct 392 ms 39428 KB Output is correct
29 Correct 399 ms 39544 KB Output is correct
30 Correct 387 ms 39612 KB Output is correct
31 Correct 441 ms 37380 KB Output is correct
32 Correct 1653 ms 37644 KB Output is correct
33 Correct 520 ms 37632 KB Output is correct
34 Correct 716 ms 37556 KB Output is correct
35 Correct 1 ms 8536 KB Output is correct
36 Correct 1391 ms 19296 KB Output is correct
37 Execution timed out 3026 ms 41008 KB Time limit exceeded
38 Halted 0 ms 0 KB -