QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#560478 | #8218. 水镜 | huangkaicheng | 0 | 1ms | 5960kb | C++14 | 1.5kb | 2024-09-12 15:53:24 | 2024-09-12 15:53:26 |
answer
#include<bits/stdc++.h>
using namespace std;
const long long maxn=5e5+5,INF=1e17;
int n;
long long h[maxn];
struct QUJIAN{
long long l,r;
QUJIAN friend operator + (QUJIAN x,QUJIAN y)
{
return {max(x.l,y.l),min(x.r,y.r)};
}
};
QUJIAN jiao(QUJIAN x,QUJIAN y)
{
if (x.l>=x.r-1||y.l>=y.r-1) return {1,0};
if (x.r<=y.l+1||y.r<=x.l+1) return {1,0};
return {max(x.l,y.l),min(x.r,y.r)};
}
bool check(QUJIAN x){return x.l>x.r;}
QUJIAN st[maxn][21];
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%lld",&h[i]);
for (int i=2;i<n;i++)
{
QUJIAN tmp1,tmp2;
if (h[i-1]<h[i]) tmp1={-INF,h[i-1]+h[i]};
else if (h[i-1]==h[i]) tmp1={-INF,INF};
else tmp1={h[i-1]+h[i],INF};
if (h[i+1]<h[i]) tmp2={-INF,h[i+1]+h[i]};
else if (h[i+1]==h[i]) tmp2={-INF,INF};
else tmp2={h[i+1]+h[i],INF};
// if (i==3) cout<<"here:"<<tmp1.l<<" "<<tmp1.r<<endl;
st[i][0]=jiao(tmp1,tmp2);
if (st[i][0].l>=st[i][0].r-1) st[i][0]={-INF,INF};
else if (st[i][0].l==-INF) st[i][0]={st[i][0].r,INF};
else if (st[i][0].r==INF) st[i][0]={-INF,st[i][0].l};
}
for (int j=1;j<=19;j++)
for (int i=2;i+(1<<j)<=n;i++) st[i][j]=st[i][j-1]+st[i+(1<<j-1)][j-1];
// cout<<st[2][0].l<<" "<<st[2][0].r<<endl;
// cout<<st[3][0].l<<" "<<st[3][0].r<<endl;
long long ans=0;
for (int i=1;i<n;i++)
{
QUJIAN w={-INF,INF};
int ed=i+1;
for (int j=19;j>=0;j--)
if (ed+(1<<j)<=n&&!check(w+st[ed][j]))
{
w=w+st[ed][j];
ed=ed+(1<<j);
}
// cout<<i<<" "<<ed<<endl;
ans+=ed-i;
}
printf("%lld",ans);
}
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: 5960kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 5760kb
input:
10 2 2 2 2 1 4 5 3 3 2
output:
29
result:
wrong answer 1st numbers differ - expected: '20', found: '29'
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%