QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#579184#9313. Make MaxdxrWA 1ms5576kbC++14757b2024-09-21 10:20:272024-09-21 10:20:29

Judging History

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

  • [2024-09-21 10:20:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5576kb
  • [2024-09-21 10:20:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3e5+5;
int a[N],l[N],r[N];
void solve()
{
//	int a[N],l[N],r[N];
	int n; cin>>n;
	stack<int> s;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=n;i>=1;i--)
	{
		while(!s.empty()&&a[s.top()]<a[i]) s.pop();
		r[i]=s.empty()? n+1:s.top();
		s.push(i);
	}
	while(!s.empty()) s.pop();
	for(int i=1;i<=n;i++)
	{
		while(!s.empty()&&a[s.top()]<a[i]) s.pop();
		l[i]=s.empty()?0:s.top();
		s.push(i);
	}
	ll ans=0;
	for(int i=1;i<=n;i++)cout<<l[i]<<"\t"<<r[i]<<endl;;
	for(int i=1;i<=n;i++) ans+=r[i]-l[i]-2;
	cout<<ans<<endl; 
}
int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	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: 1ms
memory: 5576kb

input:

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

output:

0	2
0	3
1
0	2
1	3
0
0	2
1	3
2	4
0	5
4	6
5	7
6	8
3
0	2
0	3
0	4
3

result:

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