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.

44 lines
836 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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