QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#577945#9313. Make MaxfufufufRE 0ms0kbC++14752b2024-09-20 15:36:372024-09-20 15:36:37

Judging History

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

  • [2024-09-20 15:36:37]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-20 15:36:37]
  • 提交

answer

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

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

	for (int i = 1; i <= n; i++) {
		while (!s1.empty() && a[s1.top()] < a[i]) {
			s1.pop();
		}
		ans += (i - s1.top() - 1);
		s1.push(i);
	}

	stack<ll>s2;
	for (int i = n; i >= 1; i--) {
		while (!s2.empty() && a[s2.top()] < a[i]) {
			s2.pop();
		}
		if (a[s2.top()] != a[i]) {
			ans += (s2.top() - i - 1);
		}
		s2.push(i);
	}
	cout << ans << endl;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

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

output:


result: