#P9023. Matrix Toggle Count

    ID: 22183 Type: Default 1000ms 256MiB

Matrix Toggle Count

Matrix Toggle Count

You are given a (01) matrix with (n) rows and (m) columns, initially filled with zeros. You need to perform (q) operations. In each operation, you are given a letter and an index. If the letter is R, you must toggle (invert) the specified row (i.e. change all (0)s to (1)s and all (1)s to (0)s). If the letter is C, you must toggle the specified column. After all operations, output the total number of (1)s in the matrix.

The effect of a toggle is defined as follows: for any cell ((i, j)) the final value is given by [ value(i, j)= (r_i+c_j) \mod 2, ] where (r_i) is (1) if the (i)-th row is toggled an odd number of times and (c_j) is (1) if the (j)-th column is toggled an odd number of times. Thus, the total number of ones is [ \text{answer}= r \times (m-c) + (n-r) \times c, ] where (r) is the count of rows with an odd number of toggles and (c) is the count of columns with an odd number of toggles.

inputFormat

The first line contains three integers (n), (m), and (q) ( (1 \leq n, m \leq 10^5, \ 1 \leq q \leq 10^5)) representing the number of rows, columns, and operations respectively.

Each of the following (q) lines contains an operation in the format:
op index
where op is a single character: either 'R' indicating a row toggle or 'C' indicating a column toggle. The index is a 1-indexed number denoting which row or column to toggle.

outputFormat

Output a single integer representing the total number of (1)s in the matrix after performing all operations.

sample

3 3 2
R 1
C 3
4