QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#566949#9313. Make MaxKidding_MaWA 0ms3552kbC++171.1kb2024-09-16 04:08:072024-09-16 04:08:08

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 04:08:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3552kb
  • [2024-09-16 04:08:07]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;
using i64 = int64_t;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    list<int> l;
    priority_queue<pair<int, int>> q;
    vector<int> cnt(n, 1);
    vector<list<int>::iterator> d(n);
    for (int i = 0; i < n; i++) {
        q.emplace(a[i], i);
        l.push_back(i);
        d[i] = prev(l.end());
    }

    int ans = 0;
    while (!q.empty() && l.size() > 1) {
        auto [ai, i] = q.top();
        q.pop();

        auto it = d[i];
        int j;
        if (it == prev(l.end())) {
            j = *prev(it);
        } else if (it == l.begin()) {
            j = *next(it);
        } else {
            j = (a[*prev(it)] < a[*next(it)] ? *prev(it) : *next(it)); 
        }
        cnt[j] += cnt[i];
        if (a[j] != ai) {
            ans += cnt[i];
        }
        l.erase(it);
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3552kb

input:

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

output:

1
0
4
3

result:

wrong answer 3rd numbers differ - expected: '3', found: '4'