代码如下
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7,M=1e6+7;
int p[N],d[N],v[N],a[N],f[N],tree[M<<2];
int t,n,m,l,V;
struct node{
int l,r;
bool vis;
node(int a=0,int b=0,bool w=0){
l=a,r=b,vis=w;
}
bool operator < (const node &x)const{
return x.r>r;
}
}s[N];
void pushup(int root){
tree[root]=tree[root*2]+tree[root*2+1];
}
void init(int root,int l,int r){
if(l==r){
tree[root]=a[l];
return;
}
int mid=(l+r)/2;
init(root*2,l,mid);
init(root*2+1,mid+1,r);
pushup(root);
}
void update(int root,int L,int R,int x,int y){
if(L==R){
tree[root]+=y;
return;
}
int mid=(L+R)/2;
if(x<=mid)
update(root*2,L,mid,x,y);
else
update(root*2+1,mid+1,R,x,y);
pushup(root);
}
int query(int root,int l,int r,int x,int y){
if(x>r||y<l)
return 0;
if(l>=x&&r<=y)
return tree[root];
int mid=(l+r)/2;
return query(root*2,l,mid,x,y)+query(root*2+1,mid+1,r,x,y);
}
int main(){
// freopen("detect5.in","r",stdin);
// freopen("detect5.out2","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>t;
while(t--){
cin>>n>>m>>l>>V;
for(int i=1;i<=n;i++){
cin>>d[i]>>v[i]>>a[i];
}
for(int i=1;i<=m;i++)
cin>>p[i];
for(int i=1;i<=n;i++){
if(a[i]>0){
if(v[i]>V){
s[i]=node(d[i],l);
}
else{
int ll=d[i]+(V*V-v[i]*v[i])/2/a[i]+1;
if(ll>=l)
s[i]=node(-1,-1);
else{
s[i]=node(ll,l);
}
}
}
if(a[i]==0){
if(v[i]>V){
s[i]=node(d[i],l);
}
else s[i]=node(-1,-1);
}
if(a[i]<0){
if(v[i]>V){
int r;
if(((v[i]*v[i]-V*V))%(-2*a[i])==0)
r=d[i]+(V*V-v[i]*v[i])/2/a[i]-1;
else
r=d[i]+(V*V-v[i]*v[i])/2/a[i];
s[i]=node(d[i],min(l,r));
}
else{
s[i]=node(-1,-1);
}
}
}
for(int i=1;i<=n;i++){
if(s[i].l>p[m]){
s[i].l=-1;
s[i].r=-1;
}
}
int ans(0),num(0);
for(int i=1;i<=n;i++){
int ll=s[i].l;
int rr=s[i].r;
int r=lower_bound(p+1,p+m+1,ll)-p;
if(r>m)
continue;
if(p[r]<=rr)
ans++;
}
sort(s+1,s+1+n);
cout<<ans<<" ";
// cout<<s[1].r;
// init(1,1,n);
for(int i=1;i<=n;i++){
int x=s[i].l;
int y=s[i].r;
if(y==-1)
continue;
int r;
r=lower_bound(p+1,p+m+1,x)-p;
if(r>m||p[r]>y)
continue;
if(query(1,1,l,x,y)==0){
r=upper_bound(p+1,p+m+1,y)-p;
num++;
update(1,1,l,p[r-1],1);
}
}
cout<<m-query(1,1,l,1,l)<<'\n';
for(int i=1;i<=max(n,m);i++){
p[i]=0;
d[i]=0;
a[i]=0;
v[i]=0;
s[i]=node(-1,-1);
}
memset(tree,0,sizeof(tree));
}
return 0;
}