QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#800760#9654. Cycle Functionucup-team004AC ✓695ms6764kbC++231.4kb2024-12-06 15:20:152024-12-06 15:20:16

Judging History

你现在查看的是最新测评结果

  • [2024-12-06 15:20:16]
  • 评测
  • 测评结果:AC
  • 用时:695ms
  • 内存:6764kb
  • [2024-12-06 15:20:15]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;

using F = long double;

void solve() {
    int N, M;
    std::cin >> N >> M;
    
    F A, B;
    std::cin >> A >> B;
    
    std::vector<F> x(N);
    for (int i = 0; i < N; i++) {
        std::cin >> x[i];
    }
    
    std::sort(x.begin(), x.end());
    
    std::vector<F> pre(N + 1);
    for (int i = 0; i < N; i++) {
        pre[i + 1] = pre[i] + x[i];
    }
    
    auto get = [&](F a, F b) {
        a -= 1;
        
        if (a == 0) {
            return std::abs(b) * N;
        }
        
        F ans = 0;
        
        int k = std::lower_bound(x.begin(), x.end(), -b / a) - x.begin();
        ans += std::abs(a * pre[k] + b * k);
        ans += std::abs(a * (pre[N] - pre[k]) + b * (N - k));
        return ans;
    };
    
    for (int i = 0; i < M; i++) {
        F c, d;
        std::cin >> c >> d;
        
        F ans = get(A * c, B * c + d) + get(c * A, d * A + B);
        std::cout << ans << "\n";
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    std::cout << std::fixed << std::setprecision(10);
    
    int t;
    std::cin >> t;
    
    for (int i = 1; i <= t; i++) {
        std::cout << "Case " << i << ":\n";
        solve();
    }
    
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 695ms
memory: 6764kb

input:

100
10 7 98.510171 34.875386
58.310790 10.104277 73.557456 -19.900957 -88.469673 18.156002 -87.035856 65.254094 56.881323 20.750560
17.976235 -78.976045
-31.090760 -32.572773
89.108102 74.645953
29.757563 57.265243
-70.916943 46.112593
46.713089 67.527205
98.027668 -91.230144
7 10 -95.599243 -77.881...

output:

Case 1:
1735464.3154355727
3071243.6652009933
8791618.5627157324
2948252.8987315254
6956373.7745859204
4619719.8433335249
9602730.5381978881
Case 2:
4387179.3845834211
848266.2456345937
3214961.4003662228
8371615.1642396636
1391538.8212133811
46852.8425932011
56814.0553919537
57595.7614855136
697976...

result:

ok 519531 lines

Extra Test:

score: 0
Extra Test Passed