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

44 lines
836 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 a[N] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
void print() {
int s = 0;
for (int i = 1; i < N; i++) {
s += a[i];
cout << s % 2 << " ";
}
cout << "\n";
}
int main() {
/*
01矩阵+区间修改+单点查询 <=> 非01矩阵+单点修改+区间前缀和查询
办法:
① 区间[l,r]取反 => 单点修改:a[l]++,a[r+1]++
② 单点查询a[k] => 区间前缀和查询: sum(a[1~k])%2
*/
//将2-4取反
a[2]++, a[4 + 1]--;
print();
//将2-4再取一次反
a[2]++, a[4 + 1]--;
print();
//将3-4再取一次反
a[3]++, a[4 + 1]--;
print();
return 0;
}
/*
输出:
0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0
*/