1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| #include<bits/stdc++.h> using namespace std; #define int long long const int N = 6e5+10; int t,n,m,tot,b[N],cnt,v[N],glp[N],glx[N],Maxl[N],Maxr[N]; struct lin{ int p,x,ty,orix; } l[N]; struct tre{ int l,r,Max; }; struct SegT{ tre tr[N*4]; void pushup(int node){ tr[node].Max = max(tr[node<<1].Max,tr[node<<1|1].Max); } void build(int node,int l,int r,int flag){ if (l == r){ tr[node].l = tr[node].r = l; tr[node].Max = v[l]+flag*b[l]; return; } int mid = (l+r)>>1,lc = node<<1,rc = node<<1|1; build(lc,l,mid,flag); build(rc,mid+1,r,flag); tr[node].l = tr[lc].l; tr[node].r = tr[rc].r; pushup(node); } int query(int node,int l,int r){ if (tr[node].l>r || tr[node].r<l) return -0x3f3f3f3f; if (tr[node].l>=l && tr[node].r<=r) return tr[node].Max; return max(query(node<<1,l,r),query(node<<1|1,l,r)); } } t1,t2; bool cmp1(lin a,lin b){ return a.x<b.x; } signed main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>t; while (t--){ cnt = tot = 0; cin>>n>>m; int x,y; for (int i=1;i<=n;i++){ cin>>y>>x; glp[i] = x; glx[i] = y; l[++tot].p = x; l[tot].ty = -1; l[tot].x = y-x; l[tot].orix = y; l[++tot].p = x; l[tot].ty = 0; l[tot].x = y; l[tot].orix = y; l[++tot].p = x; l[tot].ty = 1; l[tot].x = y+x; l[tot].orix = y; b[++cnt] = y-x; v[cnt] = 0; b[++cnt] = y; v[cnt] = 0; b[++cnt] = y+x; v[cnt] = 0; } sort(b+1,b+1+cnt); cnt = unique(b+1,b+1+cnt)-b-1; sort(l+1,l+1+tot,cmp1); int pl = 0,xl = 0,cntl = 0,now = 1; for (int i=1;i<=cnt;i++){ while (l[now].x<=b[i] && now<=tot){ if (l[now].ty == 0){ pl+=l[now].p; xl+=l[now].orix; cntl++; } else if (l[now].ty == 1){ pl-=l[now].p; xl-=l[now].orix; cntl--; } now++; } v[i]+=pl+xl-cntl*b[i]; } now = tot; int pr = 0,xr = 0,cntr = 0; for (int i=cnt;i>=1;i--){ while (l[now].x>=b[i] && now>=1){ if (l[now].ty == 0){ pr+=l[now].p; xr+=l[now].orix; cntr++; } else if (l[now].ty == -1){ pr-=l[now].p; xr-=l[now].orix; cntr--; } now--; } v[i]+=pr-xr+cntr*b[i]; } for (int i=1;i<=n;i++) v[lower_bound(b+1,b+1+cnt,glx[i])-b]-=glp[i]; for (int i=1;i<=cnt;i++) Maxl[i] = max(Maxl[i-1],v[i]); Maxr[cnt+1] = 0; for (int i=cnt;i>=1;i--) Maxr[i] = max(Maxr[i+1],v[i]); t1.build(1,1,cnt,-1); t2.build(1,1,cnt,1); for (int i=1;i<=n;i++){ int l = lower_bound(b+1,b+1+cnt,glx[i]-glp[i])-b,mid = lower_bound(b+1,b+1+cnt,glx[i])-b,r = lower_bound(b+1,b+1+cnt,glx[i]+glp[i])-b; int ans = max(Maxl[l-1],Maxr[r+1]); ans = max(ans,max(t1.query(1,l,mid)-glp[i]+glx[i],t2.query(1,mid+1,r)-glp[i]-glx[i])); if (ans<=m) cout<<1; else cout<<0; } cout<<"\n"; } return 0; }
|