Problem 990
Cells with Odd Values in a Matrix
Easy · 10 pts · Matrix, Math, Simulation
Problem
An R × C matrix starts with all zeros. Each of Q operations (r, c) adds 1 to every cell in row r and to every cell in column c (so cell (r, c) itself gets 2). After all operations, count the cells with an odd value. Simulating every addition works, but it is enough to count how often each row and each column was chosen: a cell is odd when its row count plus its column count is odd.
Input
The first line contains R, C and Q. Each of the next Q lines contains a row index and a column index (0-based).
Output
Print the number of cells with odd values.
Constraints
1 <= R, C <= 50; 1 <= Q <= 100
Example input
2 3 2 0 1 1 1
Example output
6
Explanation
In a 2 × 3 matrix, the operations (0, 1) and (1, 1) leave 1 3 1 / 1 3 1, where every cell is odd. So the answer is 6.