QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#559767 | #8218. 水镜 | ccccccyd | 0 | 1ms | 9832kb | C++14 | 1.0kb | 2024-09-12 09:17:32 | 2024-09-12 09:17:33 |
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;
struct node{
ll l,r;
}f0[N],f1;
int n; ll a[N],L[N],R[N];
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]) L[i]=min(a[i-1],a[i+1])+a[i];
if(a[i-1]>=a[i]&&a[i]<=a[i+1]) R[i]=max(a[i-1],a[i+1])+a[i];
}
int k=1,j=1; ll ans=0;
f0[j].l=f1.l-inf,f0[j].r=f1.r=inf;
rep(i,1,n){
//[l,mid) [mid,r]
//W(l,r) = (l+1,r-1)
if(k<i-1) f1.l=max(f1.l,L[i-1]);
if(k<i-1) f1.r=min(f1.r,R[i-1]);
while(j<k&&max(f0[j].l,f1.l)>=min(f0[j].r,f1.r)) j++;
if(j>=k){
k=j=i-1;
f0[j].l=f1.l-inf,f0[j].r=f1.r=inf;
while(j&&f0[j].l<f0[j].r){
f0[j-1].l=max(f0[j].l,L[j]),f0[j-1].r=min(f0[j].r,R[j]);
j--;
} j++;
}
// printf("%d %d\n",j,i);
ans+=i-j;
}
cout<<ans;
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 0ms
memory: 9768kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 7
Accepted
time: 0ms
memory: 9732kb
input:
10 2 2 2 2 1 4 5 3 3 2
output:
20
result:
ok 1 number(s): "20"
Test #3:
score: 7
Accepted
time: 1ms
memory: 9768kb
input:
10 2 2 1 2 2 2 1 4 1 4
output:
17
result:
ok 1 number(s): "17"
Test #4:
score: 7
Accepted
time: 0ms
memory: 9832kb
input:
10 1 5 2 2 5 4 4 4 1 3
output:
20
result:
ok 1 number(s): "20"
Test #5:
score: 7
Accepted
time: 1ms
memory: 9832kb
input:
10 904418845477 67070474418 839309493679 528132965435 512894488193 602880026087 180594485896 804608714469 235337679831 584564033737
output:
33
result:
ok 1 number(s): "33"
Test #6:
score: 7
Accepted
time: 0ms
memory: 9740kb
input:
10 2550179579 103777915839 144714526810 113623620429 670640709602 630479108288 925117980861 409440663027 851501568790 70823805701
output:
24
result:
ok 1 number(s): "24"
Test #7:
score: 7
Accepted
time: 1ms
memory: 9832kb
input:
10 814733530324 125370066936 893046741545 865528217532 707538863565 13490262680 251316040999 984630720558 697932598323 635301702897
output:
28
result:
ok 1 number(s): "28"
Test #8:
score: 0
Wrong Answer
time: 1ms
memory: 9732kb
input:
10 501904615091 622412193418 211917353535 453793869542 275851842760 930019650158 919242753532 856846287041 5971781899 267788891712
output:
24
result:
wrong answer 1st numbers differ - expected: '25', found: '24'
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%