QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85778#5693. 众数xiafan8050WA 9ms5112kbC++201.4kb2023-03-08 15:12:172023-03-08 15:12:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-08 15:12:19]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:5112kb
  • [2023-03-08 15:12:17]
  • 提交

answer

/**
 * @author: XiaFan
 * @date: 2023-03-08 14:01
 **/
#include <bits/stdc++.h>
using i64 = long long;

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

    int n;
    std::cin >> n;
    std::vector<i64> a(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    std::vector<int> b(n);
    std::iota(b.begin(), b.end(), 0);
    std::sort(b.begin(), b.end(), [&](int x, int y) {
        return a[x] < a[y];
    });
    std::vector<bool> vis(n);
    std::vector<i64> ssum(n);
    i64 ans = 0, sum = 0;
    int lastid = -1;
    for (int i = n - 1, j = 0; i >= 0; i--) {
        if (vis[i]) {
            continue;
        }
        vis[i] = true;
        
        for (; j < n; j++) {
            int id = b[j];
            if (a[id] > a[i]) {
                break;
            } else {
                sum += a[id];
                vis[id] = true;
            }
        }

        if (lastid != -1) {
            sum -= a[lastid];
        }
        if (j < n) {
            sum += a[i];
        }
        ssum[i] = sum;
        if (lastid == -1) {
            ans += 1LL * (i + 1) * ssum[i];
        } else {
            ans += 1LL * (i + 1) * (ssum[i] - ssum[lastid]);
        }
        lastid = i;
    }
    
    // for (auto i : ssum) {
    //     std::cerr << i << " ";
    // }
    std::cout << ans << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 9ms
memory: 5112kb

input:

99991
3 3 3 4 3 6 4 2 2 5 3 2 3 5 3 3 2 1 2 3 4 2 3 4 3 3 3 4 3 3 3 2 3 2 3 2 4 3 3 2 3 5 3 5 4 2 4 3 3 1 3 2 2 3 4 2 3 3 2 2 4 5 3 2 3 3 1 3 3 4 1 3 4 5 1 1 3 4 2 4 3 2 5 3 3 2 2 2 4 2 4 2 2 4 2 4 3 3 2 3 2 2 1 4 3 1 3 1 2 2 3 1 1 5 2 1 2 2 3 3 1 4 4 4 3 3 3 3 1 3 3 5 5 4 4 3 3 3 4 3 6 5 3 1 1 2 2 ...

output:

4973056115561

result:

wrong answer 1st lines differ - expected: '4973056284288', found: '4973056115561'