QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#566926#9313. Make Maxsunup15WA 0ms3772kbC++20893b2024-09-16 03:36:152024-09-16 03:36:15

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 03:36:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3772kb
  • [2024-09-16 03:36:15]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long

void solve(){
	
	int n;
	std::cin >> n;
	
	std::vector<int> a(n + 2, INT32_MAX - 1);
	for (int i = 1; i <= n; i++) std::cin >> a[i];
	
	int ans = 0;
	std::vector<std::pair<int,int>> stk;
	
	std::function<void()> fun = [&]() -> void {
		stk.push_back({INT32_MAX, 0});
		for (int i = 1; i <= n; i++) {
			if (stk.back().first > a[i]) {
				stk.push_back({a[i], i});
			} else {
				while (stk.back().first <= a[i]) {
					ans += i - stk.back().second - 1;
					stk.pop_back();
				}
				stk.push_back({a[i], i});
			}
		}
		while (stk.size()) stk.pop_back();
	};
	
	fun();
	std::reverse(a.begin(),a.end());
	fun();
	
	std::cout << ans << '\n';
}


signed main(){
	
	std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
	
	int _ = 1;
	std::cin >> _;
	while (_) solve(), --_;
	
	return (0^_^0);
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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'