-51 33 2
#include <bits/stdc++.h> #define dbg(x) std::cerr << #x << "=" << x << "\n" using i64 = long long; struct node { i64 x, y, w; int id, circle, rank; bool operator>(node b) { if (circle != b.circle) return circle > b.circle; if (b.x < 0) return (x * b.y - y * b.x > 0) && (x < 0); else if (b.x > 0) return (x * b.y - y * b.x > 0) || (x < 0); else if (b.y > 0) return (x != 0) || (y < 0); else return x < 0; } bool operator()(const node& a, const node& b) { if (a.circle != b.circle) return a.circle > b.circle; if (b.x < 0) return (a.x * b.y - a.y * b.x > 0) && (a.x < 0); else if (b.x > 0) return (a.x * b.y - a.y * b.x > 0) || (a.x < 0); else if (b.y > 0) return (a.x != 0) || (a.y < 0); else return a.x < 0; } bool operator==(node b) { if (x * b.x >= 0 && y * b.y >= 0)//同号的情况 return y * b.x == x * b.y && circle == b.circle; return false; } bool operator>=(node b) { return *this > b || *this == b; } }; std::priority_queue<node, std::vector<node>, node> q; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; i64 L; std::cin >> n >> L; std::vector<node> v(n), vv(1); vv[0].x = -114514, vv[0].y = -114514; for (int i = 0; i < n; i++) { std::cin >> v[i].x >> v[i].y >> v[i].w; v[i].id = i; v[i].circle = 0; } std::sort(v.begin(), v.end(), [&](node i, node j) { return i.x * i.x + i.y * i.y < j.x * j.x + j.y * j.y; }); int lp = 0; node now_status = v[0]; while (lp < n && v[lp].x * v[lp].x + v[lp].y * v[lp].y <= L * L) {//初始化 q.push(v[lp]); lp++; } int rank = 1; while (!q.empty()) { auto p = q.top(); q.pop(); // dbg(p.circle); // dbg(p.x); // dbg(p.y); L += p.w; now_status = p; p.rank = p == vv.back() ? vv.back().rank : rank; vv.push_back(p); while (lp < n && v[lp].x * v[lp].x + v[lp].y * v[lp].y <= L * L) {//左指针后移 if (v[lp] >= now_status) q.push(v[lp]); else { v[lp].circle = now_status.circle;//加够圈数 if (now_status > v[lp]) v[lp].circle += 1; q.push(v[lp]); } lp++; } rank++; } while (lp < n) {//所有够不着的点 v[lp].rank = -1; vv.push_back(v[lp]); lp++; } std::sort(vv.begin() + 1, vv.end(), [&](node i, node j) { return i.id < j.id; }); for (int i = 1; i <= n; i++) { std::cout << vv[i].rank << " \n"[i == n]; } return 0; }