#include<bits/stdc++.h>
using namespace std;
const int num=277200;
int m,v[200002],s[200001],dp[200001],tree[200001];
long long a[200001],c[200001],f[200001];
struct node{
long long t,x;
};
node b[200001];
bool cmp1(node x,node y)
{
return x.x<y.x;
}
bool cmp2(int x,int y)
{
return c[x]<c[y]||c[x]==c[y]&&x<y;
}
int lowbit(int x)
{
return x&-x;
}
void edit(int x,int k)
{
while(x<=m)
{
tree[x]=max(tree[x],k);
x+=lowbit(x);
}
}
int query(int x)
{
int ans=0;
while(x>0)
{
ans=max(ans,tree[x]);
x-=lowbit(x);
}
return ans;
}
int binary_search(int l,int r,long long x)
{
if(l>r)
return r;
int mid=(l+r)/2;
if(a[mid]<=x)
return binary_search(mid+1,r,x);
else
return binary_search(l,mid-1,x);
}
int main()
{
freopen("WOWO.in","r",stdin);
freopen("WOWO.out","w",stdout);
int temp,n,pos;
long long l,end;
cin>>temp;
for(int i=1;i<=temp;i++)
{
cin>>n>>m>>l>>end;
l*=num;
end*=num;
for(int j=1;j<n;j++)
{
cin>>a[j];
a[j]*=num;
}
a[n]=l;
for(int j=1;j<=n;j++)
{
cin>>v[j];
f[j]=(a[j]-a[j-1])/v[j]+f[j-1];
}
v[n+1]=1;
for(int j=1;j<=m;j++)
{
cin>>b[j].x>>b[j].t;
b[j].x*=num;
b[j].t*=num;
}
m++;
b[m].x=l;
b[m].t=end;
sort(b+1,b+m+1,cmp1);
for(int j=1;j<=m;j++)
{
pos=binary_search(1,n,b[j].x);
c[j]=b[j].t-(f[pos]+(b[j].x-a[pos])/v[pos+1]);
s[j]=j;
}
if(c[m]<0)
cout<<-1<<endl;
else
{
sort(s+1,s+m+1,cmp2);
for(int j=1;j<=m;j++)
if(c[s[j]]>=0)
{
dp[s[j]]=query(s[j])+1;
edit(s[j],dp[s[j]]);
}
cout<<m-dp[m]<<endl;
for(int j=1;j<=m;j++)
tree[j]=0;
}
}
return 0;
}123
这是 2026年10月15日 存档的第 3 版,不是当前版本。查看当前版本