답안 #298900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
298900 2020-09-14T09:50:46 Z mhy908 원 고르기 (APIO18_circle_selection) C++14
7 / 100
3000 ms 391132 KB
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(all(x))
#define press(x) x.erase(unique(all(x)), x.end());
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
const int INF=1e9;
const LL LLINF=1e18;

vector<int> vc;
//struct SEGMENT_TREE{
    set<pii> ss[2400010];
    void update(int point, int s, int e, int num, pii val, bool ad){
        if(ad)ss[point].insert(val);
        else ss[point].erase(val);
        if(s==e)return;
        if(num<=(s+e)/2)update(point*2, s, (s+e)/2, num, val, ad);
        else update(point*2+1, (s+e)/2+1, e, num, val, ad);
    }
    void query(int point, int s, int e, int sx, int ex, int sy, int ey){
        if(e<sx||s>ex)return;
        if(sx<=s&&e<=ex){
            auto it=ss[point].lower_bound(mp(sy, 0));
            while(it!=ss[point].end()){
                if(it->F>ey)break;
                vc.eb(it->S);
                it++;
            }
            return;
        }
        query(point*2, s, (s+e)/2, sx, ex, sy, ey);
        query(point*2+1, (s+e)/2+1, e, sx, ex, sy, ey);
    }
//}seg;

int n, ans[300010], l[300010], r[300010];
pair<pii, pii> arr[300010];
vector<int> idx;
bool cmp(pair<pii, pii> a, pair<pii, pii> b){return mp(a.S.F, -a.S.S)>mp(b.S.F, -b.S.S);}
bool is_con(int a, int b){
    LL d=(LL)(arr[a].F.F-arr[b].F.F)*(arr[a].F.F-arr[b].F.F)+(LL)(arr[a].F.S-arr[b].F.S)*(arr[a].F.S-arr[b].F.S);
    LL rs=(LL)(arr[a].S.F+arr[b].S.F)*(arr[a].S.F+arr[b].S.F);
    return rs>=d;
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%d %d %d", &arr[i].F.F, &arr[i].F.S, &arr[i].S.F);
        idx.eb(arr[i].F.F-arr[i].S.F);
        idx.eb(arr[i].F.F+arr[i].S.F);
        arr[i].S.S=i;
    }
    sort(arr+1, arr+n+1, cmp);
    svec(idx); press(idx);
    for(int i=1; i<=n; i++){
        l[i]=lower_bound(all(idx), arr[i].F.F-arr[i].S.F)-idx.begin()+1;
        r[i]=lower_bound(all(idx), arr[i].F.F+arr[i].S.F)-idx.begin()+1;
        update(1, 1, idx.size(), l[i], mp(arr[i].F.S-arr[i].S.F, i), 1);
        update(1, 1, idx.size(), l[i], mp(arr[i].F.S+arr[i].S.F, i), 1);
        update(1, 1, idx.size(), r[i], mp(arr[i].F.S-arr[i].S.F, i), 1);
        update(1, 1, idx.size(), r[i], mp(arr[i].F.S+arr[i].S.F, i), 1);
    }
    for(int i=1; i<=n; i++){
        if(ans[arr[i].S.S])continue;
        query(1, 1, idx.size(), l[i], r[i], arr[i].F.S-arr[i].S.F, arr[i].F.S+arr[i].S.F);
        //svec(vc); press(vc);
        //printf("%d : ", arr[i].S.S);
        for(auto j:vc){
            if(ans[arr[j].S.S])continue;
            //printf("%d ", arr[j].S.S);
            if(is_con(i, j)){
                ans[arr[j].S.S]=arr[i].S.S;
                update(1, 1, idx.size(), l[j], mp(arr[j].F.S-arr[j].S.F, j), 0);
                update(1, 1, idx.size(), l[j], mp(arr[j].F.S+arr[j].S.F, j), 0);
                update(1, 1, idx.size(), r[j], mp(arr[j].F.S-arr[j].S.F, j), 0);
                update(1, 1, idx.size(), r[j], mp(arr[j].F.S+arr[j].S.F, j), 0);
            }
        }
        //puts("");
        vc.clear();
    }
    for(int i=1; i<=n; i++)printf("%d ", ans[i]);
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
circle_selection.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   57 |         scanf("%d %d %d", &arr[i].F.F, &arr[i].F.S, &arr[i].S.F);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 113144 KB Output is correct
2 Correct 85 ms 113016 KB Output is correct
3 Correct 77 ms 113120 KB Output is correct
4 Correct 77 ms 113016 KB Output is correct
5 Correct 78 ms 113016 KB Output is correct
6 Correct 80 ms 113376 KB Output is correct
7 Correct 76 ms 113144 KB Output is correct
8 Correct 78 ms 113272 KB Output is correct
9 Correct 76 ms 113144 KB Output is correct
10 Correct 78 ms 113272 KB Output is correct
11 Correct 76 ms 113272 KB Output is correct
12 Correct 75 ms 113144 KB Output is correct
13 Correct 77 ms 113144 KB Output is correct
14 Correct 79 ms 113176 KB Output is correct
15 Correct 76 ms 113144 KB Output is correct
16 Correct 92 ms 115320 KB Output is correct
17 Correct 92 ms 115320 KB Output is correct
18 Correct 91 ms 115320 KB Output is correct
19 Correct 195 ms 126584 KB Output is correct
20 Correct 168 ms 126584 KB Output is correct
21 Correct 206 ms 126568 KB Output is correct
22 Correct 171 ms 121848 KB Output is correct
23 Correct 194 ms 123512 KB Output is correct
24 Correct 172 ms 121592 KB Output is correct
25 Correct 165 ms 121208 KB Output is correct
26 Correct 186 ms 121540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3077 ms 391132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 113016 KB Output is correct
2 Execution timed out 3082 ms 357608 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3084 ms 390184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 113144 KB Output is correct
2 Correct 85 ms 113016 KB Output is correct
3 Correct 77 ms 113120 KB Output is correct
4 Correct 77 ms 113016 KB Output is correct
5 Correct 78 ms 113016 KB Output is correct
6 Correct 80 ms 113376 KB Output is correct
7 Correct 76 ms 113144 KB Output is correct
8 Correct 78 ms 113272 KB Output is correct
9 Correct 76 ms 113144 KB Output is correct
10 Correct 78 ms 113272 KB Output is correct
11 Correct 76 ms 113272 KB Output is correct
12 Correct 75 ms 113144 KB Output is correct
13 Correct 77 ms 113144 KB Output is correct
14 Correct 79 ms 113176 KB Output is correct
15 Correct 76 ms 113144 KB Output is correct
16 Correct 92 ms 115320 KB Output is correct
17 Correct 92 ms 115320 KB Output is correct
18 Correct 91 ms 115320 KB Output is correct
19 Correct 195 ms 126584 KB Output is correct
20 Correct 168 ms 126584 KB Output is correct
21 Correct 206 ms 126568 KB Output is correct
22 Correct 171 ms 121848 KB Output is correct
23 Correct 194 ms 123512 KB Output is correct
24 Correct 172 ms 121592 KB Output is correct
25 Correct 165 ms 121208 KB Output is correct
26 Correct 186 ms 121540 KB Output is correct
27 Correct 478 ms 141688 KB Output is correct
28 Correct 464 ms 141432 KB Output is correct
29 Correct 482 ms 141560 KB Output is correct
30 Correct 359 ms 133368 KB Output is correct
31 Correct 332 ms 131576 KB Output is correct
32 Correct 322 ms 131320 KB Output is correct
33 Execution timed out 3073 ms 356900 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 113144 KB Output is correct
2 Correct 85 ms 113016 KB Output is correct
3 Correct 77 ms 113120 KB Output is correct
4 Correct 77 ms 113016 KB Output is correct
5 Correct 78 ms 113016 KB Output is correct
6 Correct 80 ms 113376 KB Output is correct
7 Correct 76 ms 113144 KB Output is correct
8 Correct 78 ms 113272 KB Output is correct
9 Correct 76 ms 113144 KB Output is correct
10 Correct 78 ms 113272 KB Output is correct
11 Correct 76 ms 113272 KB Output is correct
12 Correct 75 ms 113144 KB Output is correct
13 Correct 77 ms 113144 KB Output is correct
14 Correct 79 ms 113176 KB Output is correct
15 Correct 76 ms 113144 KB Output is correct
16 Correct 92 ms 115320 KB Output is correct
17 Correct 92 ms 115320 KB Output is correct
18 Correct 91 ms 115320 KB Output is correct
19 Correct 195 ms 126584 KB Output is correct
20 Correct 168 ms 126584 KB Output is correct
21 Correct 206 ms 126568 KB Output is correct
22 Correct 171 ms 121848 KB Output is correct
23 Correct 194 ms 123512 KB Output is correct
24 Correct 172 ms 121592 KB Output is correct
25 Correct 165 ms 121208 KB Output is correct
26 Correct 186 ms 121540 KB Output is correct
27 Execution timed out 3077 ms 391132 KB Time limit exceeded
28 Halted 0 ms 0 KB -