# LOJ #6062. 「2017 山东一轮集训 Day2」Pair

## Solution

#include<bits/stdc++.h>
#define ls (o<<1)
#define rs (o<<1|1)
using namespace std;
const int N=150010;
int n,m,H,a[N],b[N],tr[N*4],la[N*4];
inline void pushdown(int o){
if(!la[o])return ;
tr[ls]+=la[o];tr[rs]+=la[o];la[ls]+=la[o];la[rs]+=la[o];la[o]=0;
}
inline int qry(int l,int r,int o,int sa,int se){
if(sa<=l && r<=se)return tr[o];
int mid=(l+r)>>1;pushdown(o);
if(se<=mid)return qry(l,mid,ls,sa,se);
if(sa>mid)return qry(mid+1,r,rs,sa,se);
return min(qry(l,mid,ls,sa,mid),qry(mid+1,r,rs,mid+1,se));
}
inline void ins(int l,int r,int o,int sa,int se,int t){
if(sa<=l && r<=se){tr[o]+=t;la[o]+=t;return ;}
int mid=(l+r)>>1;pushdown(o);
if(se<=mid)ins(l,mid,ls,sa,se,t);
else if(sa>mid)ins(mid+1,r,rs,sa,se,t);
else ins(l,mid,ls,sa,mid,t),ins(mid+1,r,rs,mid+1,se,t);
tr[o]=min(tr[ls],tr[rs]);
}
inline void build(int l,int r,int o){
if(l==r){tr[o]=l;return ;}
int mid=(l+r)>>1;
build(l,mid,ls);build(mid+1,r,rs);
tr[o]=min(tr[ls],tr[rs]);
}
int main(){
freopen("pp.in","r",stdin);
freopen("pp.out","w",stdout);
cin>>n>>m>>H;
for(int i=1;i<=m;i++)scanf("%d",&b[i]);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
sort(b+1,b+m+1);
for(int i=1;i<=n;i++)a[i]=m-(lower_bound(b+1,b+m+1,H-a[i])-b)+1;
build(0,m,1);
int ans=0;
for(int i=1;i<=n;i++){
ins(0,m,1,a[i],m,-1);
if(i>m)ins(0,m,1,a[i-m],m,1);
if(i>=m && tr[1]>=0)ans++;
}
cout<<ans<<endl;
return 0;
}


posted @ 2018-08-04 19:40  PIPIBoss  阅读(155)  评论(0编辑  收藏