Files
python/TangDou/AcWing/BIT/POJ2155_Prepare_1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

48 lines
968 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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
*/