QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#1193#741973#9722. Invaluable Assetsship2077ucup-team004Failed.2024-11-18 16:30:162024-11-18 16:30:16

详细

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题目提交者结果用时内存语言文件大小提交时间测评时间
#741973#9722. Invaluable Assetsucup-team004AC ✓555ms44712kbC++231.8kb2024-11-13 15:33:392024-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;
}