QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#585771#9313. Make MaxWeCunWA 0ms3460kbC++20753b2024-09-23 22:07:102024-09-23 22:07:11

Judging History

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

  • [2024-09-23 22:07:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3460kb
  • [2024-09-23 22:07:10]
  • 提交

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;
}

详细

Test #1:

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

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'