QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322796#8218. 水镜dengziyue0 4ms22304kbC++141.3kb2024-02-07 18:51:422024-02-07 18:51:43

Judging History

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

  • [2024-02-07 18:51:43]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:22304kb
  • [2024-02-07 18:51:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define max_n 500000
#define inf ((long long)1e13)
int n;
long long a[max_n+2];
long long sta[21][max_n+2];
long long sti[21][max_n+2];
int lg[max_n+2];
long long ans=0;
inline int querya(int l,int r){
	int lg=::lg[r-l+1];
	return max(sta[lg][l],sta[lg][r-(1<<lg)+1]);
}
inline int queryi(int l,int r){
	int lg=::lg[r-l+1];
	return min(sti[lg][l],sti[lg][r-(1<<lg)+1]);
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("P10144_1.in","r",stdin);
	freopen("P10144_1.out","w",stdout);
	#endif
	scanf("%d",&n);
	for(int i=1;i<=n;++i){scanf("%lld",a+i); a[i]<<=2;}
	for(int i=1;i<=n;++i){sta[0][i]=0; sti[0][i]=inf;}
	sti[0][1]=sti[0][n]=inf;
	for(int i=2;i<n;++i){
		long long l1=0,r1=inf,l2=0,r2=inf,l,r;
		if(a[i-1]<a[i])r1=(a[i-1]+a[i])/2;
		if(a[i-1]>a[i])l1=(a[i-1]+a[i])/2;
		if(a[i+1]<a[i])r2=(a[i+1]+a[i])/2;
		if(a[i+1]>a[i])l2=(a[i+1]+a[i])/2;
		l=max(l1,l2); r=min(r1,r2);
		if(l==0)sta[0][i]=r;
		if(r==inf)sti[0][i]=l;
	}
	for(int j=1;j<=20;++j){
		for(int i=1;i+(1<<j)-1<=n;++i){
			sta[j][i]=max(sta[j-1][i],sta[j-1][i+(1<<(j-1))]);
			sti[j][i]=min(sti[j-1][i],sti[j-1][i+(1<<(j-1))]);
		}
	}
	for(int i=2;i<=n;++i)lg[i]=lg[i>>1]+1;
	for(int l=1,r=2;l<n;++l){
		r=max(r,l+1);
		while(r+1<=n&&querya(l+1,r)<queryi(l+1,r))++r;
		ans+=r-l;
	}
	printf("%lld\n",ans);
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 2ms
memory: 13988kb

input:

2
2 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 3ms
memory: 22228kb

input:

10
2 2 2 2 1 4 5 3 3 2

output:

20

result:

ok 1 number(s): "20"

Test #3:

score: 0
Accepted
time: 4ms
memory: 22216kb

input:

10
2 2 1 2 2 2 1 4 1 4

output:

17

result:

ok 1 number(s): "17"

Test #4:

score: 0
Accepted
time: 0ms
memory: 22304kb

input:

10
1 5 2 2 5 4 4 4 1 3

output:

20

result:

ok 1 number(s): "20"

Test #5:

score: -7
Wrong Answer
time: 0ms
memory: 22280kb

input:

10
904418845477 67070474418 839309493679 528132965435 512894488193 602880026087 180594485896 804608714469 235337679831 584564033737

output:

45

result:

wrong answer 1st numbers differ - expected: '33', found: '45'

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%