QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#30494 | #3300. Cactus Competition | Y25t | WA | 4ms | 9960kb | C++20 | 1.3kb | 2022-04-29 10:27:04 | 2022-04-29 10:27:22 |
Judging History
answer
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define N 200005
int n,m,a[N],b[N],bb=inf;
#define W 18
int f[N][W],g[N][W],h[N][W];
#define pii std::pair<int,int>
std::vector<pii> st;
long long ans;
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
scanf("%d",&b[i]),bb=std::min(bb,b[i]);
for(int i=1;i<=m;i++)
f[i][0]=g[i][0]=b[i];
for(int j=1;j<W;j++)
for(int i=1;i+(1<<j)-1<=m;i++){
f[i][j]=std::max(f[i][j-1],f[i+(1<<(j-1))][j-1]);
g[i][j]=std::min(g[i][j-1],g[i+(1<<(j-1))][j-1]);
}
a[n+1]=-inf;
st.emplace_back(inf,0);
for(int i=1;i<=n;i++){
while(st.size()&&st.back().first<=a[i])
st.pop_back();
st.emplace_back(a[i],i);
int x=0,mn=inf;
for(int j=W-1;~j;j--)
if(x+(1<<j)<=m&&f[x+1][j]+a[i]<0)
mn=std::min(mn,g[x+1][j]),x+=1<<j;
mn=std::min(mn,b[++x]);
h[i][0]=std::prev(std::upper_bound(st.begin(),st.end(),pii(-mn,0),std::greater<pii>()))->second;
}
for(int j=1;j<W;j++)
for(int i=1;i+(1<<j)-1<=n;i++)
h[i][j]=std::min(h[i][j-1],h[i+(1<<(j-1))][j-1]);
for(int i=n,y=n+1;i;i--){
if(a[i]+bb>=0)
y=i;
int x=i-1;
for(int j=W-1;~j;j--)
if(x+(1<<j)<=n&&h[x+1][j]>=i)
x+=(1<<j);
ans+=std::max(0,x-y+1);
}
printf("%lld\n",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 9960kb
input:
3 3 -1 0 1 -1 0 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 3ms
memory: 9916kb
input:
3 3 -1 0 1 1 0 1
output:
5
result:
ok single line: '5'
Test #3:
score: 0
Accepted
time: 4ms
memory: 9960kb
input:
10 10 145195799 312862766 143966779 -11056226 -503624929 636383890 -182650312 -382759112 -290767690 377894950 -845235881 -418232930 -600566938 -957917357 -181139226 125255273 -175406945 740226783 -750456842 325848662
output:
0
result:
ok single line: '0'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 9932kb
input:
10 10 923415743 -503391272 885740174 329644337 -693052351 -53764994 731859967 -834732760 -57751504 151969590 553689579 313784278 -12090771 921222379 -378313551 819586787 -373658045 559813071 671861309 268258615
output:
38
result:
wrong answer 1st lines differ - expected: '13', found: '38'