QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#568010#9313. Make MaxtsaiRE 0ms0kbC++14901b2024-09-16 14:56:512024-09-16 14:56:53

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 14:56:53]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-16 14:56:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[250000]={0};
void solve(){
	ll n;
	scanf("%d",&n);
	stack<ll>down;
	ll maxi=-1;
	for(ll i=1;i<=n;i++){
		scanf("%d",&i[a]);
		maxi=max(maxi,a[i]);
	}
	ll ans=0;
	a[n+1]=maxi;
	for(ll i=1;i<=n+1;i++){
		if(down.empty()||a[down.top()]>=a[i]){
			down.push(i);
		}else{
			stack<ll>calc;
			ll tmp;
			while(!down.empty()&&a[down.top()]<a[i]){
				while(!calc.empty()&&a[calc.top()]==a[down.top()]){
					calc.pop();
				}
				calc.push(down.top());
				down.pop();
			}
			tmp=-1;
			while(!calc.empty()){
				ans+=i-calc.top();
				tmp=(tmp==-1?calc.top():tmp*1);
				calc.pop();
			}
			down.push(tmp);
			a[tmp]=a[i];
			down.push(i);
		}
	}
	printf("%d",ans);
	return ;
}

int main(){
	ll t;
	scanf("%d",&t);
	while(t--){
		solve();
		if(t) printf("\n");
	}
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

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

output:


result: