QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#323443#8218. 水镜Larunatrecy0 0ms0kbC++141.4kb2024-02-09 21:01:102024-02-09 21:01:11

Judging History

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

  • [2024-02-09 21:01:11]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-02-09 21:01:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+7;
typedef long long LL;
LL a[N];
int n;
#define PII pair<LL,LL>
#define mk(x,y) make_pair(x,y)
#define X(x) x.first
#define Y(x) x.second
PII seg[N],tr[N*4];
PII operator +(PII A,PII B){return mk(max(X(A),X(B)),min(Y(A),Y(B)));}
const LL F = 1e13;
void build(int k,int l,int r)
{
	if(l==r)
	{
		tr[k]=seg[l];
		return;
	}
	int mid=(l+r)>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	tr[k]=tr[k<<1]+tr[k<<1|1];
}
PII query(int k,int l,int r,int L,int R)
{
	if(L<=l&&r<=R)return tr[k];
	int mid=(l+r)>>1;
	if(R<=mid)return query(k<<1,l,mid,L,R);
	if(L>mid)return query(k<<1|1,mid+1,r,L,R);
	return query(k<<1,l,mid,L,mid)+query(k<<1|1,mid+1,r,mid+1,R);
}
bool check(int l,int r)
{
	if(r-l+1<=2)return 1;
	PII I=query(1,2,n-1,l+1,r-1);
	if(X(I)<Y(I))return 1;
	return 0;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(int i=2;i<=n-1;i++)
	{
		PII I=mk(0,F);
		//pi-1<=pi
		if(a[i-1]<a[i])I=I+mk(0,a[i-1]+a[i]);
		if(a[i-1]>a[i])I=I+mk(a[i-1]+a[i],F);
		if(a[i]>a[i+1])I=I+mk(0,a[i]+a[i+1]);
		if(a[i]<a[i+1])I=I+mk(a[i]+a[i+1],F);
		seg[i]=mk(0-1,F+1);
		if(X(I)==0)X(seg[i])=Y(I);
		if(Y(I)==F)Y(seg[i])=X(I);
	}
	build(1,2,n-1);
	int l=1;
	LL ans=0;
	for(int i=1;i<=n;i++)
	{
		while(l<=i&&!check(l,i))l++;
		ans+=i-l+1;
	}
	printf("%lld\n",ans-n);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Memory Limit Exceeded

Test #1:

score: 0
Memory Limit Exceeded

input:

2
2 1

output:


result:


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%