QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#585766#9313. Make MaxWeCunWA 0ms3568kbC++14753b2024-09-23 22:06:162024-09-23 22:06:22

Judging History

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

  • [2024-09-23 22:06:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3568kb
  • [2024-09-23 22:06:16]
  • 提交

answer

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

typedef long long ll;

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	vector<int> stk(n + 2), l(n + 2), r(n + 2);
	int top = 0;
	stk[top] = 0;
	for(int i = 1; i <= n; i++)
	{
		while(top && a[i] > stk[top]) top--;
		l[i] = stk[top] + 1;
		stk[++top] = i;
	}
	
	top = 0;
	stk[top] = n + 1;
	for(int i = n; i >= 1; i--)
	{
		while(top && a[i] > stk[top]) top--;
		r[i] = stk[top] - 1;
		if(a[stk[top]] == a[i]) r[i] = i;
		stk[++top] = i;
	}
	
	ll ans = 0;
	for(int i = 1; i <= n; i++) ans += r[i] - l[i];
	
	cout << ans << endl;
}

int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1
1
0
3

result:

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