QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#595644#9313. Make MaxWwjqWA 1ms5636kbC++14906b2024-09-28 14:10:342024-09-28 14:10:36

Judging History

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

  • [2024-09-28 14:10:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5636kb
  • [2024-09-28 14:10:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
long long a[200010];
int r[200010],l[200010];
int main ()
{
	int t,i;
	cin>>t;
	long long n,ans=0;
	stack<long long>q;
	
	while(t--)
	{
		cin>>n;
		ans=0;
		stack<long long>q;
		for(i=1;i<=n;i++)
			cin>>a[i];
		//you
		for(i=1;i<=n;i++)
		{
			while(q.size()&&a[q.top()]<=a[i])
			{
				r[q.top()]=i;
				q.pop();
			}
			q.push(i);
		}
//		for(i=1;i<=n;i++)
//			cout<<r[i]<<" ";
//		cout<<'\n';
		while(q.size())
		{
			r[q.top()]=n+1;
			q.pop();
		}
		for(i=n;i>=1;i--)
		{
			while(q.size()&&a[q.top()]<=a[i])
			{
				l[q.top()]=i;
				q.pop();
			}
			q.push(i);
		}
//		for(i=1;i<=n;i++)
//			cout<<l[i]<<" ";
//			cout<<'\n';
		while(q.size())
		{
			r[q.top()]=0;
			q.pop();
		}
		for(i=1;i<=n;i++)
		{
			ans+=r[i]-i-1;
			if (a[l[i]]!=a[i])
			ans+=i-l[i]-1;
		}
		cout<<ans<<'\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5636kb

input:

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

output:

-4
-2
-4
-9

result:

wrong answer 1st numbers differ - expected: '1', found: '-4'