제출 #701408

#제출 시각아이디문제언어결과실행 시간메모리
701408Abrar_Al_Samit원 고르기 (APIO18_circle_selection)C++17
12 / 100
1364 ms55244 KiB
#include<bits/stdc++.h>
using namespace std;

const int nax = 3e5 + 3;
long long sqrd(int x) {
  return x * 1LL * x;
}
struct circle {
  int x, y, r, j;

  bool operator< (const circle& b) const {
    if(r!=b.r) return r > b.r;
    return j < b.j;
  }

  bool intersect(const circle& b) const {
    return sqrd(x-b.x) + sqrd(y-b.y) <= sqrd(r+b.r);
  }
} bag[nax];

bool cmp(circle a, circle b) {
  return make_pair(a.x, a.r) < make_pair(b.x, b.r);
}
void PlayGround() {
  int n;
  cin>>n;


  set<pair<int,int>>b, c;
  set<pair<int,int>,greater<pair<int,int>>>a;
  for(int i=0; i<n; ++i) {
    int x, y, r;
    cin>>x>>y>>r;

    bag[i] = {x, y, r, i+1};

    a.insert({2*r, n-i});
    b.insert({x-r, i});
    c.insert({x+r, i});
  }

  int ans[n+1];
  while(!a.empty()) {
    auto x = *a.begin();
    a.erase(x);

    //cerr<<n-x.second<<endl;

    circle cur = bag[n-x.second];

    vector<int>cache;

    while(1) {
      auto it = b.lower_bound(make_pair(cur.x-cur.r, 0));
      if(it==b.end() || it->first>cur.x+cur.r) break;

      cache.push_back(it->second);
      circle rem = bag[it->second];
      b.erase(make_pair(rem.x-rem.r, rem.j-1));
      c.erase(make_pair(rem.x+rem.r, rem.j-1));
    }

    while(1) {
      auto it = c.lower_bound(make_pair(cur.x-cur.r, 0));
      if(it==c.end() || it->first>cur.x+cur.r) break;

      cache.push_back(it->second);
      circle rem = bag[it->second];
      b.erase(make_pair(rem.x-rem.r, rem.j-1));
      c.erase(make_pair(rem.x+rem.r, rem.j-1));
    }

    for(int x : cache) {
      ans[x+1] = cur.j;
      a.erase(make_pair(2 * bag[x].r, n-x));
    }
  }
  for(int i=1; i<=n; ++i) {
    cout<<ans[i]<<' ';
  }


  // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 0;
}
#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...