## [$10117$. 「一本通 $4.1$ 练习 $2$」简单题](https://loj.ac/p/10117) #### 题目解析 区间修改+单点查询,用树状数组维护差分数组,从而记录每个点反转的次数。最后单点查询点反转的次数%2即为应得值。 ### $Code$ ```cpp {.line-numbers} #include using namespace std; const int N = 100005; int n, m; // 树状数组模板 #define lowbit(x) (x & -x) typedef long long LL; int c[N]; void add(int x, int v) { while (x < N) c[x] += v, x += lowbit(x); } LL sum(int x) { LL res = 0; while (x) res += c[x], x -= lowbit(x); return res; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int t, x, y; scanf("%d", &t); if (t == 1) { scanf("%d%d", &x, &y); add(x, 1), add(y + 1, -1); // 用差分数组+树状数组,模拟区间修改 } else { scanf("%d", &x); printf("%d\n", sum(x) % 2); // 单点查询,是否变化 } } return 0; } ```