QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578142#9313. Make MaxfufufufWA 0ms3524kbC++141.0kb2024-09-20 16:55:472024-09-20 16:55:49

Judging History

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

  • [2024-09-20 16:55:49]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3524kb
  • [2024-09-20 16:55:47]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const ll maxn = (ll)2e5 + 7;
//求出左边第一个比他大的元素和右边第一个比他大的元素
ll a[maxn];
ll n;
void solve() {
    cin>>n;
    vector<ll> a(n + 2);
    a[0] = a[n + 1] = 2e9;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    //左边第一个绝对比他小的元素
    vector<ll> stk={ 0 };
    for (int i = 1; i <= n; i++) {
        while (!stk.empty() and a[stk.back()] <= a[i]) {
            stk.pop_back();
        }
        ans += i - stk.back() - 1;
        stk.push_back(i);
    }

    //右边第一个绝对比他小的元素
    stk = { n + 1 };
    for (int i = n; i >= 1; i--) {
        while (!stk.empty() and a[stk.back()] <= a[i]) {
            stk.pop_back();
        }
        if (a[stk.back()] != a[i]) ans += stk.back() - i - 1;
        stk.push_back(i);
    }

    cout << ans << '\n';
}

ll T;
int main() {
	cin >> T;
	while (T--) {
		solve();
	}
}

详细

Test #1:

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

input:

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

output:

1
2
30
3

result:

wrong answer 2nd numbers differ - expected: '0', found: '2'