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 125 126 127 128
|
#include <bits/stdc++.h> using namespace std; #define resetIO(x) \ freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout) #define debug(fmt, ...) \ fprintf(stderr, "[%s:%d] " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__) namespace fastio { const int MAXBUF = 1 << 21; char buf[MAXBUF], *p1 = buf, *p2 = buf; char pbuf[MAXBUF], *pp = pbuf; inline char getc() { return (p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, MAXBUF, stdin)), *p1++; } inline void putc(char c) { (pp == pbuf + MAXBUF) && (fwrite(pbuf, 1, MAXBUF, stdout), pp = pbuf), *pp++ = c; } inline void print_final() { fwrite(pbuf, 1, pp - pbuf, stdout), pp = pbuf; } }; using namespace fastio; template <class _Tp> inline _Tp& read(_Tp& x) { bool sign = false; char ch = getc(); for (; !isdigit(ch); ch = getc()) sign |= (ch == '-'); for (x = 0; isdigit(ch); ch = getc()) x = x * 10 + (ch ^ 48); return sign ? (x = -x) : x; } template <class _Tp> inline void write(_Tp x) { if (x < 0) putc('-'), x = -x; if (x > 9) putc(x / 10); putc((x % 10) ^ 48); } bool m_be; using ll = long long; const int MAXN = 5e5 + 10; const int INF = 0x3f3f3f3f; struct SegmentTree { #define li (i << 1) #define ri (i << 1 | 1) #define lson li, l, mid #define rson ri, mid + 1, r int pos[MAXN * 4]; bool cls[MAXN * 4]; vector<int> vec[MAXN * 4]; void build(int i, int l, int r) { pos[i] = 0; sort(vec[i].begin(), vec[i].end()); if (l == r) return; int mid = (l + r) >> 1; build(lson), build(rson); } void insert(int i, int l, int r, int q, int v) { vec[i].emplace_back(v); if (l == r) return; int mid = (l + r) >> 1; q <= mid ? insert(lson, q, v) : insert(rson, q, v); } int count(int i, int p) { return upper_bound(vec[i].begin(), vec[i].end(), p) - vec[i].begin() - pos[i]; } void pushdown(int i) { if (cls[i]) cls[i] = 0, cls[li] = cls[ri] = 1, pos[li] = pos[ri] = 0; if (pos[i] == pos[li] + pos[ri]) return; int x = vec[i][pos[i] - 1]; pos[li] += count(li, x - 1), pos[ri] += count(ri, x - 1); int p = pos[i] - pos[li] - pos[ri], t = count(li, x); (p <= t) ? (pos[li] += p) : (pos[li] += t, pos[ri] += p - t); } int query(int i, int l, int r, int ql, int qr, int p) { if (ql > qr) return 0; if (ql <= l && r <= qr) return count(i, p); int mid = (l + r) >> 1, ret = 0; pushdown(i); if (ql <= mid) ret += query(lson, ql, qr, p); if (qr > mid) ret += query(rson, ql, qr, p); return ret; } int bound(int i, int l, int r, int p, int k) { if (l == r) return pos[i] += k, l; int mid = (l + r) >> 1; pushdown(i); int tmp = count(li, p), ret; if (k <= tmp) ret = bound(lson, p, k); else pos[li] += tmp, ret = bound(rson, p, k - tmp); return pos[i] = pos[li] + pos[ri], ret; } } sgt; int n, q, m, a[MAXN], b[MAXN], k[MAXN]; bool m_ed; signed main() { resetIO(teams); read(n); for (int i = 1; i <= n; ++i) read(a[i]), read(b[i]); for (int i = 1; i <= n; ++i) sgt.insert(1, 1, n, b[i], a[i]); sgt.build(1, 1, n); read(q); while (q--) { bool ans = 1; ll sum = 0; read(m); for (int i = 1; i <= m; ++i) read(k[i]), sum += k[i]; if (sum > n) { putc('0'), putc('\n'); continue; } sort(k + 1, k + m + 1); sgt.cls[1] = 1, sgt.pos[1] = 0; for (int i = 1; i <= m; ++i) { int rem = k[i] + sgt.query(1, 1, n, 1, k[i] - 1, k[i]); if (sgt.count(1, k[i]) < rem) { ans = 0; break; } sgt.bound(1, 1, n, k[i], rem); } putc(ans ? '1' : '0'), putc('\n'); } return print_final(), 0; }
|