题解
2025-07-14 09:41:25
发布于:浙江
3阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
struct Event {
long long time;
int type;
int idx;
int w;
bool operator<(const Event& other) const {
if (time != other.time) return time < other.time;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> w(n), s(n), t(n);
vector<Event> events;
for (int i = 0; i < n; ++i) {
cin >> w[i] >> s[i] >> t[i];
events.push_back({(long long)s[i] * 10, 0, i, w[i]});
events.push_back({(long long)t[i] * 10 + 1, 1, i, w[i]});
}
sort(events.begin(), events.end());
const int MAX_W = 1e5;
vector<int> cnt(MAX_W + 2, 0);
multiset<int> active;
vector<int> val(n, 0);
for (const auto& e : events) {
if (e.type == 0) {
if (!active.empty()) {
int min_w = *active.begin();
if (min_w <= e.w) {
val[e.idx] = e.w - min_w;
} else {
val[e.idx] = 0;
}
} else {
val[e.idx] = 0;
}
if (cnt[e.w] == 0) {
active.insert(e.w);
}
cnt[e.w]++;
} else {
cnt[e.w]--;
if (cnt[e.w] == 0) {
active.erase(active.find(e.w));
}
}
}
for (int i = 0; i < n; ++i) {
cout << val[i] << (i == n - 1 ? '\n' : ' ');
}
return 0;
}
这里空空如也
有帮助,赞一个