QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#221690#7616. Jump Graphucup-team1951#WA 0ms4120kbC++201.3kb2023-10-21 14:15:442023-10-21 14:15:45

Judging History

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

  • [2023-10-21 14:15:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4120kb
  • [2023-10-21 14:15:44]
  • 提交

answer

#include <vector>
#include <cstdio>
#include <utility>
#include <tuple>
#include <algorithm>

using ll = long long;

int main() {
    int n;
    std::scanf("%d", &n);
    std::vector<ll> p(n);
    for (int i = 0; i < n; i++) {
        std::scanf("%lld", &p[i]);
    }

    auto solve = [](std::vector<ll> &p) {
        int n = p.size();
        std::vector<std::tuple<ll, ll, ll>> stack;
        std::vector<ll> ans(n);
        ll sum = 0;

        for (int i = 0; i < n; i++) {
            ll cx = 1, ax = 0;
            while (!stack.empty() && std::get<0>(stack.back()) < p[i]) {
                auto [k, c, a] = stack.back();
                stack.pop_back();
                cx += c;
                ax += c + a;
                sum -= c + a;
            }
            stack.push_back({p[i], cx, ax});
            // std::printf("{%d, %d, %lld}\n", p[i], cx, ax);
            ans[i] = sum + ax;
            sum += cx + ax;
        }

        return ans;
    };

    std::vector<ll> ans1 = solve(p);
    std::reverse(p.begin(), p.end());
    std::vector<ll> ans2 = solve(p);
    std::reverse(ans2.begin(), ans2.end());
    
    for (int i = 0; i < n; i++) {
        std::printf("%lld ", ans1[i] + ans2[i]);
    }
    std::printf("\n");
}

详细

Test #1:

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

input:

6
1 6 3 2 5 4

output:

11 7 7 7 6 8 

result:

ok single line: '11 7 7 7 6 8 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

2
1 2

output:

1 1 

result:

ok single line: '1 1 '

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3896kb

input:

36
9 29 1 3 14 31 24 21 10 18 22 16 8 7 15 12 17 19 25 28 27 34 11 6 32 4 20 13 2 35 23 26 33 36 30 5

output:

101 98 99 99 100 87 81 79 79 79 73 72 71 71 70 72 72 77 83 94 107 100 120 120 116 118 116 116 116 113 142 142 143 143 175 175 

result:

wrong answer 1st lines differ - expected: '92 89 90 90 91 78 73 71 71 71 ...110 107 136 136 137 136 168 168', found: '101 98 99 99 100 87 81 79 79 7...16 113 142 142 143 143 175 175 '