QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#322794 | #8218. 水镜 | dengziyue | 0 | 0ms | 22356kb | C++14 | 1.3kb | 2024-02-07 18:45:51 | 2024-02-07 18:45:52 |
Judging History
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;
else l1=(a[i-1]+a[i])/2;
if(a[i]>a[i+1])r2=(a[i]+a[i+1])/2;
else 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 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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 0ms
memory: 14212kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -7
Wrong Answer
time: 0ms
memory: 22356kb
input:
10 2 2 2 2 1 4 5 3 3 2
output:
39
result:
wrong answer 1st numbers differ - expected: '20', found: '39'
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%