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