#P6532. XOR Chessboard Attack
XOR Chessboard Attack
XOR Chessboard Attack
There is an \( n \times n \) chessboard with \( k \) pieces. The \( i\)-th piece has a combat power \( w_i \). The rules are as follows:
- A piece can attack all cells in its row and column, except the cell it is in.
- A cell is considered attacked if and only if the XOR (\( \oplus \)) of the combat powers of all pieces that can attack that cell is greater than 0.
Initially, the board is set with the given pieces. Then there will be \( p \) operations. In each operation, you are given an update in the form of two integers \( i \) and \( new\_w \) which means that the \( i\)-th piece's combat power changes from its old value to \( new\_w \). After each update, output the total number of attacked cells on the board.
Note: The pieces are numbered from 1 to \( k \) in the order they are given in the input. A cell \( (r,c) \) is attacked if and only if \( R[r] \oplus C[c] \gt 0 \), where \( R[r] \) is the XOR of the combat powers of all pieces in row \( r \) and \( C[c] \) is the XOR of those in column \( c \). Since any cell, regardless of whether it contains a piece or not, gets attacked by the pieces on its row and column (excluding the piece if it sits in that cell), the final attacked count can be computed by noting that a cell is not attacked if \( R[r] = C[c] \) (because \( R[r] \oplus C[c] = 0 \)).
The total number of cells on the board is \( n^2 \). If we let \( f(v) \) be the number of rows with XOR value \( v \) and \( g(v) \) be the number of columns with XOR value \( v \), then the number of cells that are not attacked is \( \sum_{v} f(v) \times g(v) \), and the number of attacked cells is \( n^2 - \sum_{v} f(v) \times g(v) \).
inputFormat
The input is given as follows:
n k p r1 c1 w1 r2 c2 w2 ... rk ck wk i1 new_w1 i2 new_w2 ... ip new_wp
Here, \( n \) is the size of the chessboard, \( k \) is the number of pieces, and \( p \) is the number of operations. Each of the next \( k \) lines contains three integers \( r \), \( c \), \( w \) representing the row, column (1-indexed) and combat power of a piece. Each of the following \( p \) lines contains two integers \( i \) and \( new\_w \), meaning that the combat power of the \( i\)-th piece is updated to \( new\_w \>.
outputFormat
For each of the \( p \) operations, output a single line containing one integer — the total number of attacked cells after that operation.
sample
3 2 2
1 1 1
2 3 2
1 3
2 1
6
6
</p>