Submission #658358

#TimeUsernameProblemLanguageResultExecution timeMemory
658358RichemCircle selection (APIO18_circle_selection)C++14
100 / 100
2660 ms1014712 KiB
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <time.h>
#pragma once
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
struct uint64_hash {
  static inline uint64_t rotr(uint64_t x, unsigned k) {
    return (x >> k) | (x << (8U * sizeof(uint64_t) - k));
  }
 
  static inline uint64_t hash_int(uint64_t x) noexcept {
    auto h1 = x * (uint64_t)(0xA24BAED4963EE407);
    auto h2 = rotr(x, 32U) * (uint64_t)(0x9FB21C651E98DF25);
    auto h = rotr(h1 + h2, 32U);
    return h;
  }
 
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
    return hash_int(x + FIXED_RANDOM);
  }
};
 
template <typename K, typename V, typename Hash = uint64_hash>
using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>;
template <typename K, typename Hash = uint64_hash>
using hash_set = hash_map<K, __gnu_pbds::null_type, Hash>;
template <typename T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, std::less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
 
using namespace std;
 
const int MAX_CERCLE = 3e5+42, INF = 1e9;
 
struct Cercle{
    unsigned int xCentre, yCentre, rayon, id;
 
    bool operator<(Cercle autre) {
        if(rayon == autre.rayon)
            return id < autre.id;
        return rayon > autre.rayon;
    }
};
 
int nbCercle;
Cercle cercle[MAX_CERCLE];
 
void input() {
    cin >> nbCercle;
 
    for(int idCercle = 0; idCercle < nbCercle; idCercle++) {
        cin >> cercle[idCercle].xCentre >> cercle[idCercle].yCentre >> cercle[idCercle].rayon;
        cercle[idCercle].xCentre += INF;
        cercle[idCercle].yCentre += INF;
        cercle[idCercle].id = idCercle;
    }
    sort(cercle, cercle + nbCercle);
}
 
hash_map<long long, vector<int>> grille;
bool enleve[MAX_CERCLE] = {0};
 
int quiEnleve[MAX_CERCLE];
 
unsigned int tailleGrille = (1 << 31);
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    input();
 
    for(int grand = 0; grand < nbCercle; grand++) {
        if(enleve[grand])
            continue;
 
        bool change = 0;
        while(tailleGrille/2 >= cercle[grand].rayon) {
            tailleGrille /= 2;
            change = 1;
        }
 
        if(change) {
            grille.clear();
            for(int cur = 0; cur < nbCercle; cur++) {
                if(enleve[cur])
                    continue;
                long long xGrille = (long long)cercle[cur].xCentre / tailleGrille;
                int yGrille = cercle[cur].yCentre / tailleGrille;
                
                grille[(xGrille << 32) + yGrille].push_back(cur);
            }
        }
 
        long long xGrille = (long long)cercle[grand].xCentre / tailleGrille, yGrille = (long long)cercle[grand].yCentre / tailleGrille;
 
        vector<int> quiReste;
        for(int deltaX = -2; deltaX <= 2; deltaX++) {
            for(int deltaY = -2; deltaY <= 2; deltaY++) {
                long long nouvX = xGrille + deltaX, nouvY = yGrille + deltaY;
                auto &v = grille[(nouvX << 32) + nouvY];
 
                //for(int type = 0; type < 2; type++) {
 
                    for(int id = v.size()-1; id >= 0; id--) {
                        int autre = v[id];
                        
                        long long xDist = (long long)cercle[grand].xCentre - cercle[autre].xCentre, yDist = (long long)cercle[grand].yCentre - cercle[autre].yCentre;
                        long long rDist = (long long)cercle[grand].rayon + cercle[autre].rayon;
 
                        if(xDist * xDist + yDist * yDist <= rDist * rDist && !enleve[autre]) {
                            enleve[autre] = 1;
                            quiEnleve[cercle[autre].id] = cercle[grand].id;
                            
                            swap(v[id], v[v.size()-1]);
                            v.pop_back();
                        }
                    }
               // }
            }
        }
 
        for(auto nouveau : quiReste) {
            if(enleve[nouveau])
                continue;
            long long xGrille = (long long)cercle[nouveau].xCentre / tailleGrille;
            int yGrille = cercle[nouveau].yCentre / tailleGrille;
            
            grille[(xGrille << 32) + yGrille].push_back(nouveau);
        }
    }
 
    for(int cur = 0; cur < nbCercle; cur++) {
        cout << quiEnleve[cur]+1 << " ";
    }
}
/*
11
9 9 2
13 2 1 11 8 2 3 3 2 3 12 1 12 14 1 9 8 5 2 8 2 5 2 1 14 4 2 14 14 1
*/

Compilation message (stderr)

circle_selection.cpp:6:9: warning: #pragma once in main file
    6 | #pragma once
      |         ^~~~
#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...