You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.1 KiB
1.1 KiB
10117
. 「一本通 4.1
练习 2
」简单题
题目解析
区间修改+单点查询,用树状数组维护差分数组,从而记录每个点反转的次数。最后单点查询点反转的次数%2即为应得值。
Code
#include <bits/stdc++.h>
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;
}