QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#585677#9313. Make MaxlqxWA 1ms7936kbC++17682b2024-09-23 21:44:162024-09-23 21:44:17

Judging History

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

  • [2024-09-23 21:44:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7936kb
  • [2024-09-23 21:44:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int n,a[N],l[N],r[N];
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	a[0]=a[n+1]=1e18;
	stack<int> st;
	st.push(0);
	for(int i=1;i<=n;i++){
		while(a[st.top()]<a[i])st.pop();
		l[i]=st.top()+1;
		st.push(i);
	}
	while(!st.empty())st.pop();
	st.push(n+1);
	for(int i=n;i>=0;i--){
		while(a[st.top()]<a[i])st.pop();
	r[i]=st.top()-1;
	st.push(i);
	}
	for(int i=n;i>=1;i--){
		if(a[i]==a[r[i]+1]){
			r[i]=i;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=r[i]-l[i];
	}
	cout<<ans<<'\n';
	return 0;
}

详细

Test #1:

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

input:

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

output:

1

result:

wrong answer Answer contains longer sequence [length = 4], but output contains 1 elements