제출 #258765

#제출 시각아이디문제언어결과실행 시간메모리
258765MercenaryCircle selection (APIO18_circle_selection)C++14
100 / 100
1168 ms26756 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 3e5 + 5;
const int logn = log2(maxn) + 1;
int ans[maxn];
int n;

struct circle{
    int x , y , r , id;
    bool operator < (const circle & other){
        return mp(x,y) < mp(other.x,other.y);
    }
}a[maxn] , b[maxn] , c[maxn];

bool intersect(circle & a , circle & b){
    return 1ll * (a.r + b.r) * (a.r + b.r) >= 1ll * (a.x - b.x) * (a.x - b.x) + 1ll * (a.y - b.y) * (a.y - b.y);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i].x >> a[i].y >> a[i].r;
        a[i].id = i;
        c[i] = a[i];
    }
    sort(a + 1 , a + n + 1 ,[&](const circle & x , const circle &y){
            return mp(x.r , -x.id) > mp(y.r , -y.id);
         });
    int cur = a[1].r * 2;
    for(int i = 1 ; i <= n ; ++i){
        if(ans[a[i].id] > 0)continue;
        if(a[i].r <= cur / 2){
            cur /= 2;
            for(int j = 1 ; j <= n ; ++j){
                b[j].x = a[j].x / cur;
                b[j].y = a[j].y / cur;
                b[j].id = a[j].id;
            }
            sort(b + 1 , b + n + 1);
        }
        ans[a[i].id] = a[i].id;
        int x = a[i].x / cur;
        int y = a[i].y / cur;
        for(int j = x - 2 ; j <= x + 2 ; ++j){
            auto it = lower_bound(b + 1 , b + n + 1, circle{j , y - 3 , 0 , 0}) - b;
            while(it <= n && b[it].x == j && b[it].y <= y + 2){
                if(ans[b[it].id] == 0 && intersect(a[i] , c[b[it].id]))ans[b[it].id] = a[i].id;
                ++it;
            }
        }
    }
    for(int i = 1 ; i <= n ; ++i)cout << ans[i] << ' ';
}

컴파일 시 표준 에러 (stderr) 메시지

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:38:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:39:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...