QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578407#9313. Make MaxgoliterWA 1ms7848kbC++14711b2024-09-20 18:55:432024-09-20 18:55:44

Judging History

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

  • [2024-09-20 18:55:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7848kb
  • [2024-09-20 18:55:43]
  • 提交

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

詳細信息

Test #1:

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

input:

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

output:

1
-3
-3
-21

result:

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