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
|
#pragma GCC optimize(2) #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <cctype> #include <vector> #include <cmath> #include <unordered_map> using namespace std; #define pii pair<int,int> #define mp make_pair #define ll long long #define int long long
char buf[1 << 20], *p1, *p2; #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)?EOF: *p1++) template <typename T> inline void read(T &t) { int v = getchar();T f = 1;t = 0; while (!isdigit(v)) {if (v == '-')f = -1;v = getchar();} while (isdigit(v)) {t = t * 10 + v - 48;v = getchar();} t *= f; } template <typename T,typename... Args> inline void read(T &t,Args&... args) { read(t);read(args...); }
const int N = 2e5 + 10;
struct node { int id,pos,cnt; friend inline bool operator < (const node &a,const node &b) { return a.pos < b.pos; }; }q[N];
struct que { int pos,cnt,opt,flag; friend inline bool operator < (const que &a,const que &b) { return a.pos < b.pos; }; }l[N<<3];
int n,m,x[N],pos[N],pre[N],suf[N],tot = 0; unordered_map <int,int> ans;
void add(int i) { l[++tot] = (que){x[i] - pos[i],pos[i] - x[i],1,1}; l[++tot] = (que){x[i] + 1,x[i] + pos[i],0,1}; l[++tot] = (que){x[i] + 1,- x[i] + pos[i],1,0}; l[++tot] = (que){x[i] + pos[i] + 1,x[i] + pos[i],0,0}; }
void solve() { read(n,m);ans.clear();tot = 0; for (int i = 1;i <= n;++i) { read(x[i],pos[i]); q[i] = (node){i,x[i],0}; add(i); } sort(q+1,q+1+n);sort(l+1,l+1+tot); int now = 1; int c1 = 0,c2 = 0,s1 = 0,s2 = 0; for (int i = 1;i <= n;++i) { while (now <= tot && l[now].pos <= q[i].pos) { if (l[now].opt) { if (l[now].flag) ++c1,s1 += l[now].cnt; else --c1,s1 -= l[now].cnt; } else { if (l[now].flag) ++c2,s2 += l[now].cnt; else --c2,s2 -= l[now].cnt; } ++now; } q[i].cnt = q[i].pos; q[i].cnt *= (c1 - c2); q[i].cnt += s1 + s2; } for (int i = 1;i <= n;++i) { if (q[i].cnt > m) { suf[i] = (q[i].cnt - m) + q[i].pos; pre[i] = (q[i].cnt - m) - q[i].pos; } else { pre[i] = suf[i] = -1e18; } } pre[0] = suf[n+1] = -1e18; for (int i = 1;i <= n;++i) pre[i] = max(pre[i],pre[i-1]); for (int i = n;i >= 1;--i) suf[i] = max(suf[i],suf[i+1]); for (int i = 1;i <= n;++i) { ans[q[i].pos] = max(ans[q[i].pos], max(suf[i] - q[i].pos,pre[i] + q[i].pos)); } for (int i = 1;i <= n;++i) { if (pos[i] >= ans[x[i]]) putchar('1'); else putchar('0'); } puts(""); }
signed main() { int T;read(T); while (T--) solve(); return 0; }
|