답안 #968094

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968094 2024-04-23T07:39:22 Z socpite 원 고르기 (APIO18_circle_selection) C++14
7 / 100
3000 ms 37136 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);
        // cout << id << " " << st[id] << endl;
        id >>= 1;
    }
}

bool found = 0;

void search(int x, int dep, int id){
    if(pid[id]){
        if(check(x, pid[id])){
            removed[pid[id]] = x;
            remove(pid[id]);
            found = 1;
        }
    }
    if(found)return;
    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;
        remove(v);
        removed[v] = v;
        while(true){
            found = 0;
            search(v, 0, 1);
            if(!found)break;
        }
    }
    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 8536 KB Output is correct
3 Correct 2 ms 8536 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8652 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8536 KB Output is correct
11 Correct 2 ms 8656 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 3 ms 8704 KB Output is correct
17 Correct 4 ms 8536 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 7 ms 9048 KB Output is correct
20 Correct 7 ms 9048 KB Output is correct
21 Correct 9 ms 9052 KB Output is correct
22 Correct 11 ms 8864 KB Output is correct
23 Correct 11 ms 9052 KB Output is correct
24 Correct 43 ms 9084 KB Output is correct
25 Correct 8 ms 9052 KB Output is correct
26 Correct 8 ms 9056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1265 ms 36444 KB Output is correct
2 Execution timed out 3029 ms 36360 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1346 ms 18056 KB Output is correct
3 Execution timed out 3029 ms 37136 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3078 ms 36868 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 8536 KB Output is correct
3 Correct 2 ms 8536 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8652 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8536 KB Output is correct
11 Correct 2 ms 8656 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 3 ms 8704 KB Output is correct
17 Correct 4 ms 8536 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 7 ms 9048 KB Output is correct
20 Correct 7 ms 9048 KB Output is correct
21 Correct 9 ms 9052 KB Output is correct
22 Correct 11 ms 8864 KB Output is correct
23 Correct 11 ms 9052 KB Output is correct
24 Correct 43 ms 9084 KB Output is correct
25 Correct 8 ms 9052 KB Output is correct
26 Correct 8 ms 9056 KB Output is correct
27 Correct 15 ms 9308 KB Output is correct
28 Correct 19 ms 9340 KB Output is correct
29 Correct 18 ms 9324 KB Output is correct
30 Correct 27 ms 9308 KB Output is correct
31 Correct 20 ms 9304 KB Output is correct
32 Correct 25 ms 9308 KB Output is correct
33 Correct 181 ms 18316 KB Output is correct
34 Correct 177 ms 18316 KB Output is correct
35 Execution timed out 3020 ms 18340 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8536 KB Output is correct
3 Correct 2 ms 8536 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8652 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8536 KB Output is correct
11 Correct 2 ms 8656 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 3 ms 8704 KB Output is correct
17 Correct 4 ms 8536 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 7 ms 9048 KB Output is correct
20 Correct 7 ms 9048 KB Output is correct
21 Correct 9 ms 9052 KB Output is correct
22 Correct 11 ms 8864 KB Output is correct
23 Correct 11 ms 9052 KB Output is correct
24 Correct 43 ms 9084 KB Output is correct
25 Correct 8 ms 9052 KB Output is correct
26 Correct 8 ms 9056 KB Output is correct
27 Correct 1265 ms 36444 KB Output is correct
28 Execution timed out 3029 ms 36360 KB Time limit exceeded
29 Halted 0 ms 0 KB -