QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576421#9313. Make MaxjiankiyoWA 0ms3664kbC++141.5kb2024-09-19 20:18:172024-09-19 20:18:19

Judging History

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

  • [2024-09-19 20:18:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3664kb
  • [2024-09-19 20:18:17]
  • 提交

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);
            }
        }
        while (!s.empty()) lef[s.top()] = 0, s.pop();
        long long ans = 0LL;
        for (int i = 1; i <= n; i++) {
            if ( lef[i]!= 0&&a[lef[i]] != a[i]) ans += rig[i] - lef[i] - 2;
            else if(a[lef[i]] == a[i]) continue;
            else if (lef[i]== 0)ans += rig[i] - i - 1;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

详细

Test #1:

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

input:

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

output:

0
0
0
0

result:

wrong answer 1st numbers differ - expected: '1', found: '0'