QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#379785#8574. Swirly Sortucup-team206#WA 10ms5652kbC++171.9kb2024-04-06 19:05:442024-04-06 19:05:45

Judging History

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

  • [2024-04-06 19:05:45]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:5652kb
  • [2024-04-06 19:05:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e5 + 10;
int n, k, a[N];
int bt[N];
inline void Add(int x, int y) {
    while (x) {
        bt[x] += y;
        x -= x & -x;
    }
}
inline int Ask(int x) {
    int ans = 0;
    while (x <= n) {
        ans += x;
        x += x & -x;
    }
    return ans;
}
inline int Solve() {
    multiset<int> st;
    int f0 = 0, delta0 = 0;
    for (int i = 1; i <= n; ++i) {
        f0 += a[i];
        st.insert(a[i]);
        st.insert(a[i]);
        delta0 -= 1;
        while (st.size() > -delta0) st.erase(--st.end());
    }
    int x = 0, fx = f0, delta = delta0;
    for (auto nx : st) {
        fx += delta * (nx - x);
        ++delta;
        x = nx;
    }
    return fx;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int Case;
    cin >> Case;
    while (Case--) {
        cin >> n >> k;
        for (int i = 1; i <= n; ++i) {
            cin >> a[i];
        }
        if (k == 1) {
            cout << Solve() << '\n';
            continue;
        }
        if (k == n) {
            int ans = 1e15;
            for (int r = 0; r < n; ++r) {
                ans = min(ans, Solve());
                rotate(a + 1, a + 2, a + n + 1);
            }
            cout << ans << '\n';
            continue;
        }
        if (~k & 1) {
            cout << 0 << '\n';
            continue;
        }
        vector<int> V(a + 1, a + n + 1);
        sort(V.begin(), V.end());
        int sm = 0;
        for (int i = 1; i <= n; ++i) {
            int k = lower_bound(V.begin(), V.end(), a[i]) - V.begin() + 1;
            sm += Ask(k + 1);
            Add(k, 1);
        }
        for (int i = 1; i <= n; ++i) bt[i] = 0;
        int mn = 1e9;
        for (int i = 0; i + 1 < n; ++i) mn = min(mn, V[i + 1] - V[i]);
        cout << (sm & 1 ? mn : 0) << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5652kb

input:

4
4 1
6 4 3 7
4 2
6 4 3 7
4 3
6 4 3 7
4 4
6 4 3 7

output:

3
0
1
2

result:

ok 4 number(s): "3 0 1 2"

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 5612kb

input:

10000
4 3
524728 254456 277709 19127
15 11
360089 525234 862619 897281 336644 910706 75922 708901 754517 734744 94169 326125 746826 846063 159956
4 2
140105 792522 40264 514789
12 2
270333 888927 500833 9065 936673 982631 332435 751429 607700 840339 804685 416612
8 7
119416 689632 517277 673646 8262...

output:

23253
7691
0
0
15986
278544
0
0
0
0
0
2022
0
0
0
9260
0
0
51255
0
0
277173
480146
0
658
0
25495
0
0
0
0
266148
0
767231
0
0
0
121885
0
788638
0
0
0
779611
0
0
0
0
0
0
517074
0
0
0
210836
454586
662851
0
781542
0
0
864957
175421
0
0
0
0
0
0
0
541010
0
0
0
0
0
3413333
0
321
30512
0
19677
0
3095770
0
0...

result:

wrong answer 26th numbers differ - expected: '4525', found: '0'