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
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 4e+6 + 5;
struct question { int l, r, t; }q[100005]; struct node { int lmax, rmax; unsigned short xrv, emp; }t[maxn << 2][2]; unsigned short tag[maxn << 2]; int a[maxn], n, m, cnt, lstans;
inline int rd() { register int x = 0, c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); return x; } inline void pushup(node &cur, node ls, node rs) { cur.xrv = ls.xrv ^ rs.xrv; if (ls.emp && rs.emp) { cur.xrv ^= (((ls.rmax + rs.lmax) >> 1) & 1) ^ 1; } cur.emp = ls.emp | rs.emp; cur.lmax = ls.lmax; cur.rmax = rs.rmax; if (!ls.emp) cur.lmax += rs.lmax; if (!rs.emp) cur.rmax += ls.rmax; } void build(int cur, int l, int r) { if (l == r) { if (a[l]) t[cur][0].lmax = t[cur][0].rmax = 1, t[cur][1].emp = 1; else t[cur][1].lmax = t[cur][1].rmax = 1, t[cur][0].emp = 1; return; } int mid = (l + r) >> 1; build(cur << 1, l, mid); build(cur << 1|1, mid + 1, r); pushup(t[cur][0], t[cur << 1][0], t[cur << 1|1][0]); pushup(t[cur][1], t[cur << 1][1], t[cur << 1|1][1]); } inline void tagon(int cur) { swap(t[cur][0], t[cur][1]); tag[cur] ^= 1; } inline void pushdown(int cur) { if (tag[cur]) { tagon(cur << 1); tagon(cur << 1|1); tag[cur] = 0; } } void modify(int cur, int l, int r, int L, int R) { if (L <= l && r <= R) { tagon(cur); return; } pushdown(cur); int mid = (l + r) >> 1; if (L <= mid) modify(cur << 1, l, mid, L, R); if (R > mid) modify(cur << 1|1, mid + 1, r, L, R); pushup(t[cur][0], t[cur << 1][0], t[cur << 1|1][0]); pushup(t[cur][1], t[cur << 1][1], t[cur << 1|1][1]); } node query(int cur, int l, int r, int L, int R) { if (L == l && r == R) { return t[cur][0]; } pushdown(cur); int mid = (l + r) >> 1; if (R <= mid) return query(cur << 1, l, mid, L, R); else if (L > mid) return query(cur << 1|1, mid + 1, r, L, R); else { node ret = (node){0, 0, 0, 0}; pushup(ret, query(cur << 1, l, mid, L, mid), query(cur << 1|1, mid + 1, r, mid + 1, R)); return ret; } }
int main() { n = rd(); int opt, x, y; for (int i = 1; i <= n; ++i) { opt = rd(); if (opt == 1) { x = rd(); a[++m] = x; } else { x = rd(); y = rd(); q[++cnt] = (question){x, y, m}; } } build(1, 1, m); for (int i = 1; i <= cnt; ++i) { if (lstans) { q[i].l = q[i].t - q[i].l + 1; q[i].r = q[i].t - q[i].r + 1; swap(q[i].l, q[i].r); } if (!a[q[i].l]) q[i].l++; if (q[i].l > q[i].r) lstans = 0; else { node res = query(1, 1, m, q[i].l, q[i].r); if (!res.emp) { lstans = (((q[i].r - q[i].l) >> 1) & 1) ^ 1; } else { lstans = (((res.lmax + 1) >> 1) & 1) ^ res.xrv ^ (((res.rmax >> 1) & 1) ^ 1); } } printf("%d\n", lstans); if (lstans) { if (q[i].t + 1 <= q[i + 1].t) modify(1, 1, m, q[i].t + 1, q[i + 1].t); for (int j = q[i].t + 1; j <= q[i + 1].t; ++j) a[j] ^= 1; } } return 0; }
|