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.

48 lines
968 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 11;
//树状数组模板
int tr[N];
#define lowbit(x) (x & -x)
void add(int x, int c) {
for (int i = x; i <= N; i += lowbit(i)) tr[i] += c;
}
int sum(int x) {
int res = 0;
for (int i = x; i; i -= lowbit(i)) res += tr[i];
return res;
}
void print() {
for (int i = 1; i < N; i++)
cout << sum(i) % 2 << " ";
cout << "\n";
}
int main() {
//本题的类似一维思路不需要对树状数组进行初始化因为基数组都是0
//记录基数组到树状数组中
// for (int i = 1; i < N; i++) add(i, a[i]);
// 将2-4取反
add(2, 1), add(4 + 1, -1);
print();
//将2-4再取一次反
add(2, 1), add(4 + 1, -1);
print();
//将3-4再取一次反
add(3, 1), add(4 + 1, -1);
print();
return 0;
}
/*
:
1 0 0 0 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 0 0 1 1 1 1 1 1
*/