QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578399#9313. Make MaxgoliterWA 1ms7984kbC++14709b2024-09-20 18:53:512024-09-20 18:53:51

Judging History

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

  • [2024-09-20 18:53:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7984kb
  • [2024-09-20 18:53:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4e5+5;
int n,a[N],l[N],r[N],stk[N];
int main(){
	int t;
	cin>>t;
	while(t--){
		ll ans=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
		}
		int top=0;
		for(int i=1;i<=n;i++){
			while(top&&a[i]>a[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]>a[stk[top]]){
				top--;
			}
			r[i]=stk[top]-1;
		//	if(a[r[i]+1]==a[i]){
		//		r[i]=i;
		//	}
			stk[++top]=i;
		}
		for(int i=1;i<=n;i++){
			cout<<l[i]<<" "<<r[i]<<endl;
			ans+=r[i]-l[i];
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1 1
1 2
1
4 1
2 2
-3
4 1
2 2
3 3
4 4
5 5
6 6
7 7
-3
9 1
9 2
9 3
-21

result:

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