QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559187#8218. 水镜ccccccyd0 1ms7828kbC++141.2kb2024-09-11 20:41:592024-09-11 20:41:59

Judging History

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

  • [2024-09-11 20:41:59]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:7828kb
  • [2024-09-11 20:41:59]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int i(l),i##end(r);i<=i##end;++i)
#define per(i,r,l) for(int i(r),i##end(l);i>=i##end;--i)
using namespace std;
const int N=5e5+20; const ll inf=1e18;
int n; ll a[N],L[N],R[N];
priority_queue<ll> pl,ql;
priority_queue<ll,vector<ll>,greater<ll>> pr,qr;
signed main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%lld",&a[i]),L[i]=-inf,R[i]=inf;
	rep(i,2,n-1){
		if(a[i-1]<=a[i]&&a[i]>=a[i+1]){
			if(a[i-1]<a[i+1]) L[i-1]=max(L[i-1],a[i-1]+a[i]);
			else L[i]=max(L[i],a[i]+a[i+1]);
		}
		if(a[i-1]>=a[i]&&a[i]<=a[i+1]){
			if(a[i-1]>a[i]) R[i-1]=min(R[i-1],a[i-1]+a[i]);
			else R[i]=min(R[i],a[i]+a[i+1]);
		}
	} 
	int k=1; ll ans=0;
	rep(i,2,n){//[k,i]
		if(a[i]==a[i-1]&&a[i]==a[i-2]) {
			while(!pl.empty()) pl.pop(); pl.push(-inf);
			while(!pr.empty()) pr.pop(); pr.push(inf);
			while(!ql.empty()) ql.pop();
			while(!qr.empty()) qr.pop();
			k=i-1;
		}
		pl.push(L[i-1]),pr.push(R[i-1]);
		while(pl.top()>pr.top()){
			ql.push(L[k]),qr.push(R[k]),k++;
			while(!ql.empty()&&ql.top()==pl.top()) ql.pop(),pl.pop();
			while(!qr.empty()&&qr.top()==pr.top()) qr.pop(),pr.pop();
		} 
		ans+=i-k;
	}
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 1ms
memory: 7732kb

input:

2
2 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

10
2 2 2 2 1 4 5 3 3 2

output:

21

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%