답안 #756621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
756621 2023-06-12T02:07:14 Z fanwen 원 고르기 (APIO18_circle_selection) C++17
컴파일 오류
0 ms 0 KB
/**
 *      author : pham van sam
 *      created : 12 June 2023 (Monday)
 **/

#include <bits/stdc++.h>

using namespace std;
using namespace chrono;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)

template <typename U, typename V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <typename U, typename V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }

const int MAXN = 3e5 + 5;

long long sqr(int x) { return 1LL * x * x; }

struct circle_t {
    int x, y, r; // coordinate and radius
    circle_t(int x = 0, int y = 0, int r = 0) : x(x), y(y), r(r) {};
    bool intersects(const circle_t &t) {
        return sqr(x - t.x) + sqr(y - t.y) <= sqr(r + t.r);
    }
} points[MAXN];

struct cmp {
    inline bool operator() (int i, int j) {
        return (points[i].r > points[j].r || (points[i].r == points[j].r && i < j));
    }
};

set <int, cmp> S;
int N, ans[MAXN], adj[MAXN];
map <int, vector <pair <int, int>>> mp;
void update(int i, int j) {
    if((points[i].r > points[j].r || (points[i].r == points[j].r && i < j))) return void(ans[i] = ans[j] = i);
    return void(ans[i] = ans[j] = j);
}

void process(void) {
    cin >> N;
    FOR(i, 1, N) {
        cin >> points[i].x >> points[i].y >> points[i].r;
        mp[points[i].y + points[i].r].push_back(make_pair(i, 0));
        mp[points[i].y - points[i].r].push_back(make_pair(i, 1));
    }
    FOR(i, 1, N) adj[i] = i;
    multiset <pair <int, int>> s;
    for (auto [y, cur] : mp) {
        for (auto [i, type] : cur) if(type == 1) {
            s.insert(make_pair(points[i].x, i));
        }
        for (auto [i, type] : cur) if(type == 1) {
            auto it = s.lower_bound(make_pair(points[i].x, 0));
            if(it != s.end()) if(points[i].intersects(points[it -> second])) {
                adj[i] = it -> second;
                adj[it -> second] = i;
            }
            if(it != s.begin()) {
                --it;
                if(points[i].intersects(points[it -> second])) {
                    adj[i] = it -> second;
                    adj[it -> second] = i;
                }
            }
        }
        for (auto [i, type] : cur) if(type == 0) s.erase(s.find(make_pair(points[i].x, i)));
    }
    FOR(i, 1, N) S.insert(i);
    while((int) S.size()) {
        int u = *S.begin(); S.erase(S.begin());
        ans[u] = u;
        if(adj[u] != u) {
            ans[adj[u]] = u;
            S.erase(S.find(adj[u]));
        }
    }
    FOR(i, 1, N) cout << ans[i] << " ";
}

signed main() {

    #define TASK "TASK"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    auto start_time = steady_clock::now();
    int test = 1;
    // cin >> test;
    for (int i = 1; i <= test; ++i) {
        process();
        // cout << '\n';
    }

    auto end_time = steady_clock::now();

    cerr << "\nExecution time : " << duration_cast<milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

Compilation message

In file included from /usr/include/c++/10/map:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from circle_selection.cpp:6:
/usr/include/c++/10/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = cmp; _Alloc = std::allocator<int>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type = const std::_Rb_tree_node<int>*]':
/usr/include/c++/10/bits/stl_tree.h:2101:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = cmp; _Alloc = std::allocator<int>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = int]'
/usr/include/c++/10/bits/stl_tree.h:2154:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = const int&; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = cmp; _Alloc = std::allocator<int>]'
/usr/include/c++/10/bits/stl_set.h:512:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = int; _Compare = cmp; _Alloc = std::allocator<int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, cmp, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = int]'
circle_selection.cpp:77:28:   required from here
/usr/include/c++/10/bits/stl_tree.h:780:8: error: static assertion failed: comparison object must be invocable as const
  780 |        is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~