After each rook relocation on a large board, count squares where the xor of powers of rooks in the same row or column is nonzero.
Medium7Bit manipulationHash mapMathNo attempts yetTime limit2sMemory limit64 MBMirko likes chess and programming. Ordinary chess bored him quickly, so he came up with a game that uses only rooks.
He found a chessboard with N rows and N columns and placed K rooks on it.
The rules are:
A square that holds a rook can be attacked as well.
Mirko starts from the initial layout and makes P moves. After each move, find how many squares are attacked.
A rook can be moved to any free square of the board. The move is not restricted to its own row or column.
The first line contains the integers N, K, P (1≤N≤109, 1≤K≤105, 1≤P≤105).
Each of the next K lines contains three integers R, C, X (1≤R,C≤N, 1≤X≤109), meaning that a rook of power X starts on square (R,C).
Each of the next P lines contains four integers R1, C1, R2, C2 (1≤R1,C1,R2,C2≤N), meaning that a rook moved from square (R1,C1) to square (R2,C2).
No two rooks stand on the same square at any point.
Print P lines. Line k contains the number of attacked squares after the kth move.
An explanation of the first example. After the first move every square of the board is attacked. Square (1,1), for instance, is seen by one rook only, so the XOR for that square is 1. After the second move no square is attacked. Square (1,1) is seen by both rooks, and the XOR of their powers is 0.