QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#1193 | #741973 | #9722. Invaluable Assets | ship2077 | ucup-team004 | Failed. | 2024-11-18 16:30:16 | 2024-11-18 16:30:16 |
Details
Extra Test:
Standard Program Time Limit Exceeded
input:
10 100000 10000 100000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
result:
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#741973 | #9722. Invaluable Assets | ucup-team004 | AC ✓ | 555ms | 44712kb | C++23 | 1.8kb | 2024-11-13 15:33:39 | 2024-11-13 15:33:46 |
answer
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
for (int nCase = 1; nCase <= t; ++nCase) {
int n, c, q;
std::cin >> n >> c >> q;
int k = std::sqrt(c), k1 = k + 1;
if (c * k1 > k * k1 + c * k) k = k1;
std::vector<int> h(n);
for (int i = 0; i < n; ++i) std::cin >> h[i];
std::sort(h.begin(), h.end());
auto calc = [&](int n, int x) {
int l = n / x, t = n - l * x;
return x * c + l * l * (x - t) + (l + 1) * (l + 1) * t;
};
std::vector<int> dp(c + 1), g(k, 1);
for (int i = 1, j = 1; i <= c; ++i) {
while (calc(i, j) > calc(i, j + 1)) ++j;
dp[i] = calc(i, j);
g[i % k] = dp[i] * k - i * (k * k + c);
}
std::vector<std::vector<int>> cnt(n + 1, std::vector<int>(k));
std::vector<int64_t> pre(n + 1);
for (int i = 0; i < n; ++i) {
cnt[i + 1] = cnt[i];
++cnt[i + 1][h[i] % k];
pre[i + 1] = pre[i] + h[i];
}
std::cout << "Case #" << nCase << ":\n";
while (q--) {
int v;
std::cin >> v;
int j = std::lower_bound(h.begin(), h.end(), v - c) - h.begin();
int64_t ans = (int64_t(v) * j - pre[j]) * (k * k + c);
for (int x = 0; x < k; ++x) ans += int64_t(g[x]) * cnt[j][(v - x + k) % k];
ans /= k;
for (int i = j; i < n && h[i] < v; ++i) ans += dp[v - h[i]];
std::cout << ans << "\n";
}
}
return 0;
}