QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#433244 | #7750. Revenge on My Boss | ucup-team3215 | TL | 1ms | 3572kb | C++23 | 4.7kb | 2024-06-08 09:04:53 | 2024-06-08 09:04:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
void solve() {
ll n;
cin >> n;
ll sum = 0;
vector<array<ll, 3>> a(n);
for (auto &v: a) {
for (auto &i: v)cin >> i;
sum += v[0];
}
auto eval = [&](const vector<ll> &p) {
ll res = 0;
ll sa = 0, sb = 0;
for (auto &v: a)sa += v[0];
for (auto i: views::reverse(p)) {
sb += a[i][1];
res = max(res, (sa + sb) * a[i][2]);
sa -= a[i][0];
}
return res;
};
ll l = 0, r = 1e18 + 123;
while (r - l > 1) {
ll m = (r + l) / 2;
multiset<pl> invalid, valid;
ll cur = 0;
for (auto &v: a) {
ll val = m / v[2] - sum - v[0];
invalid.insert({v[1] - v[0] - val, v[1] - v[0]});
}
while (invalid.size() + valid.size()) {
while (invalid.size() && invalid.begin()->first + cur <= 0) {
auto it = *invalid.begin();
invalid.erase(invalid.begin());
valid.insert({it.second, it.first});
}
if (valid.empty())break;
auto it = *valid.begin();
if (it.second + cur > 0 || it.first > 0) {
break;
}
valid.erase(valid.begin());
cur += it.first;
}
if (invalid.size()) {
l = m;
continue;
}
{
multiset<pl> f, s;
for (auto &[x, y]: valid) {
f.insert({x, -y});
s.insert({-y, x});
}
while (f.size()) {
auto it = *f.begin();
f.erase(*f.begin());
s.erase(s.find({it.second, it.first}));
if (s.empty() || s.begin()->first >= cur + it.first) {
cur += it.first;
continue;
}
f.insert(it);
s.insert({it.second, it.first});
it = *s.begin();
s.erase(s.begin());
f.erase(f.find({it.second, it.first}));
if (s.empty() || s.begin()->first >= cur + it.first) {
cur += it.first;
continue;
}
s.insert(it);
f.insert({it.second, it.first});
break;
}
if (f.size()) {
l = m;
continue;
}
}
r = m;
}
vector<ll> ans;
{
ll m = r;
multiset<array<ll, 3>> invalid, valid;
ll cur = 0;
for(int i = 0;i < n;++i){
auto &v = a[i];
ll val = m / v[2] - sum - v[0];
invalid.insert({v[1] - v[0] - val, v[1] - v[0], i});
}
while (invalid.size() + valid.size()) {
while (invalid.size() && (*invalid.begin())[0] + cur <= 0) {
auto it = *invalid.begin();
invalid.erase(invalid.begin());
valid.insert({it[1], it[0], it[2]});
}
if (valid.empty())break;
auto it = *valid.begin();
if (it[1] + cur > 0 || it[0] > 0) {
break;
}
valid.erase(valid.begin());
cur += it[0];
ans.push_back(it[2]);
}
{
multiset<array<ll, 3>> f, s;
for (auto &[x, y, z]: valid) {
f.insert({x, -y, z});
s.insert({-y, x, z});
}
while (f.size()) {
auto it = *f.begin();
f.erase(*f.begin());
s.erase(s.find({it[1], it[0], it[2]}));
if (s.empty() || (*s.begin())[0] >= cur + it[0]) {
cur += it[0];
ans.push_back(it[2]);
continue;
}
f.insert(it);
s.insert({it[1], it[0], it[2]});
it = *s.begin();
s.erase(s.begin());
f.erase(f.find({it[1], it[0], it[2]}));
if (s.empty() || (*s.begin())[0] >= cur + it[0]) {
cur += it[0];
ans.push_back(it[2]);
continue;
}
s.insert(it);
f.insert({it[1], it[0], it[2]});
break;
}
}
}
reverse(ans.begin(), ans.end());
for (auto x: ans) {
cout << x + 1 << " ";
}
cout << "\n";
}
int main() {
cin.tie(0)->sync_with_stdio(false);
int t;
cin >> t;
while (t--)solve();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3572kb
input:
2 4 1 1 4 5 1 5 1 9 1 9 8 1 9 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 8 3 2 7
output:
3 1 2 4 3 8 2 4 5 9 6 1 7
result:
ok correct
Test #2:
score: -100
Time Limit Exceeded
input:
1 100000 581297 102863 1 742857 42686 1 676710 233271 1 443055 491162 1 442056 28240 1 769277 331752 1 8608 369730 1 495112 525554 1 787449 938154 1 441186 850694 1 84267 925450 1 740811 32385 1 834021 37680 1 257878 564126 1 90618 914340 1 239641 463103 1 40687 343062 1 587737 458554 1 103684 48666...