QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578528#9313. Make MaxaikongskyWA 0ms3576kbC++14690b2024-09-20 19:48:462024-09-20 19:48:48

Judging History

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

  • [2024-09-20 19:48:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3576kb
  • [2024-09-20 19:48:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int a[N];
int t,n;
void solve()
{
	cin>>n;
	ll sum = 0;
	for(int i = 1;i <= n;i++)
	{
		cin>>a[i];
	}
	vector<int>s(1);
	s.push_back(1); 
	a[0] = 0x3f3f3f;
	for(int i = 1;i <= n;i++)
	{
		while(a[s.back()] < a[i]) s.pop_back();
		sum += i - s.back() - 1;
		s.push_back(i);
	}
	
	s.clear();
	s.push_back(n);
	a[n+1] = 0x3f3f3f;
	for(int i = n ;i >= 1;i--)
	{
		while(a[s.back()] < a[i]) s.pop_back();
		if(a[s.back()] != a[i]) sum += s.back() - i - 1;
		s.push_back(i); 
	}
	cout<<sum<<endl;
}
int main()
{
	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: 3576kb

input:

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

output:

0
-1
2
2

result:

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