QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#575285#9313. Make MaxDUSK777WA 0ms3872kbC++141.4kb2024-09-19 11:50:552024-09-19 11:50:56

Judging History

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

  • [2024-09-19 11:50:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3872kb
  • [2024-09-19 11:50:55]
  • 提交

answer

//
// Created by 夕 on 2024/9/16.
//
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solu(){
    ll n;
    cin >> n;
    vector <ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector <ll> rIndex(n,-1);
    vector <ll> lIndex(n,-1);
    stack <pair <ll,ll>> s; //单调栈
    for (ll i = 0; i < n; ++i) {
        while (!s.empty() && s.top().second <= a[i]) {
            ll idx = s.top().first;
            rIndex[idx] = i;
            s.pop();
        }
        s.emplace(i, a[i]);
    }
    while (!s.empty()) s.pop();
    for (ll i = n - 1; i >= 0; --i) {
        while (!s.empty() && s.top().second <= a[i]) {
            ll idx = s.top().first;
            lIndex[idx] = i;
            s.pop();
        }
        s.emplace(i, a[i]);
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (lIndex[i] != -1){
            ans += (i - 1 - lIndex[i]);
        }
        else {
            if (a[0] != a[i]){
                ans += i;
            }
        }
        if (rIndex[i] != -1){
            ans += (rIndex[i] - i - 1);
        }
        else {
            if (a[n-1] != a[i]){
                ans += (n - i - 1);
            }
        }
    }

    cout<<ans<<endl;
    for (int i = 0; i < n; ++i) {
        cout<<i<<"  "<<lIndex[i]<<"  "<<rIndex[i]<<endl;
    }
}
int main(){
    ll q;
    cin >> q;
    while (q--){
        solu();
    }
}

详细

Test #1:

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

input:

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

output:

1
0  -1  1
1  -1  -1
0
0  -1  1
1  0  -1
3
0  -1  1
1  0  2
2  1  3
3  -1  4
4  3  5
5  4  6
6  5  -1
3
0  -1  1
1  -1  2
2  -1  -1

result:

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