QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647424#9313. Make MaxqqsmrWA 0ms4100kbC++141.4kb2024-10-17 14:03:042024-10-17 14:03:07

Judging History

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

  • [2024-10-17 14:03:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4100kb
  • [2024-10-17 14:03:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
 
const int N = 2e5 + 10;
int n, a[N], lef[N], rig[N];
stack<int> s;
 
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
 
int main () {
    int t = read();
    while (t--) {
        n = read();
        for (int i = 1; i <= n; i++) a[i] = read();
        for (int i = 1; i <= n; i++) {
            if (s.empty() || a[i] < a[s.top()]) s.push(i);
            else {
                while (!s.empty() && a[i] >= a[s.top()]) {
                    rig[s.top()] = i;
                    s.pop();
                }
                s.push(i);
            }
        }
        while (!s.empty()) rig[s.top()] = n + 1, s.pop();
        for (int i = n; i; i--) {
            if (s.empty() || a[i] < a[s.top()]) s.push(i);
            else {
                while (!s.empty() && a[i] >= a[s.top()]) {
                    lef[s.top()] = i;
                    s.pop();
                }
                s.push(i);
            }
        }

        long long ans = 0LL;
        for (int i = 1; i <= n; i++) {
            if (!lef[i] || a[lef[i]] != a[i]) ans += rig[i] - lef[i] - 2;
            else ans += rig[i] - i - 1;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1
0
3
0

result:

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