QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#256230 | #7750. Revenge on My Boss | ucup-team1055 | WA | 0ms | 3600kb | C++20 | 3.9kb | 2023-11-18 18:07:31 | 2023-11-18 18:07:31 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = int(s); i < int(n); i++)
#define rrep(i, s, n) for (int i = int(n) - 1; i >= int(s); i--)
#define all(v) (v).begin(), (v).end()
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i128 = __int128_t;
template <class T> bool chmin(T &a, T b) {
if (a <= b) return false;
a = b;
return true;
}
template <class T> bool chmax(T &a, T b) {
if (a >= b) return false;
a = b;
return true;
}
void solve() {
int n;
std::cin >> n;
std::vector<ll> a(n), b(n), c(n);
ll sum_a = 0;
std::vector<int> neg, pos, zero;
rep(i, 0, n) {
std::cin >> a[i] >> b[i] >> c[i];
sum_a += a[i];
if (b[i] - a[i] < 0) {
neg.emplace_back(i);
} else if (b[i] - a[i] == 0) {
zero.emplace_back(i);
} else {
pos.emplace_back(i);
}
}
auto check = [&](ll x) -> std::vector<int> {
std::vector<int> p;
ll sum = 0;
std::sort(all(neg), [&](int i, int j) -> bool {
ll lhs = x - (sum_a * c[i] + b[i] * c[i]);
ll rhs = x - (sum_a * c[j] + b[j] * c[j]);
return i128(lhs) * c[j] > i128(rhs) * c[i];
});
for (auto i : neg) {
if (sum * c[i] + sum_a * c[i] + b[i] * c[i] > x) {
return {};
}
sum += b[i] - a[i];
p.emplace_back(i);
}
for (auto i : zero) {
if (sum * c[i] + sum_a * c[i] + b[i] * c[i] > x) {
return {};
}
sum += b[i] - a[i];
p.emplace_back(i);
}
using P = std::pair<ll, int>;
std::priority_queue<P> pq;
std::queue<int> que;
/*
std::sort(all(pos), [&](int i, int j) -> bool {
ll lhs = x - (sum_a * c[i] + b[i] * c[i]);
ll rhs = x - (sum_a * c[j] + b[j] * c[j]);
return i128(lhs) * c[j] > i128(rhs) * c[i];
});
*/
for (auto i : pos) {
sum += b[i] - a[i];
}
for (auto i : pos) {
ll ret = x - (sum_a * c[i] + b[i] * c[i]);
if (ret < 0) {
if (ret % c[i] == 0)
ret /= c[i];
else {
ret /= c[i];
ret--;
}
} else
ret /= c[i];
pq.push({ret + (b[i] - a[i]), i});
}
while (!pq.empty()) {
auto [ret, i] = pq.top();
if (sum <= ret) {
que.push(i);
pq.pop();
} else {
break;
}
}
while (!que.empty()) {
int i = que.front();
que.pop();
sum -= b[i] - a[i];
if (sum * c[i] + sum_a * c[i] + b[i] * c[i] > x) {
return {};
}
while (!pq.empty()) {
auto [ret, j] = pq.top();
if (sum <= ret) {
que.push(j);
pq.pop();
} else {
break;
}
}
}
if(!pq.empty()) {
return {};
}
std::reverse(all(p));
auto ans = pos;
ans.insert(ans.end(), all(p));
return ans;
};
ll ok = 2'000'000'000'000'000'000;
ll ng = 0;
while ((ok - ng) > 1) {
ll mid = (ok + ng) >> 1;
auto ret = check(mid);
if (ret.empty()) {
ng = mid;
} else {
ok = mid;
}
}
auto ans = check(ok);
rep(i, 0, n) {
std::cout << ans[i] + 1 << " \n"[i == n - 1];
}
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3600kb
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 2 3 4 8 5 9 7 1 6
result:
wrong answer Wrong Answer on Case#2