#C4364. Taco Toggle Visibility
Taco Toggle Visibility
Taco Toggle Visibility
You are given an n x m grid representing a seating arrangement in a hall. Each cell in the grid is initially occupied by a person who is either sitting (denoted by 'S') or standing (denoted by 'T'). Two persons can see each other if they are both standing and they are in the same row or the same column, provided that there is no sitting person between them. In other words, for any contiguous segment of standing persons in a row or column, each unordered pair of persons in that segment can see each other. The number of visible pairs in a segment of length k is given by the combination formula: \( \binom{k}{2} = \frac{k(k-1)}{2} \).
You are also given a series of q commands. Each command toggles the state of a person at a specified position (i.e. if the person is sitting, they will stand up, and if they are standing, they will sit down). After each command, you are required to compute the total number of pairs of standing people who can see each other in the entire grid.
Input Example:
4 4 SSSS STTT SSSS STSS 3 2 2 3 4 4 2
Output Example:
3 2 3
inputFormat
The first line contains two integers n and m, representing the number of rows and columns of the grid, respectively.
The next n lines each contain a string of length m, where each character is either 'S' or 'T', representing the initial state of each cell in the grid.
The following line contains an integer q, the number of toggle commands.
The next q lines each contain two integers r and c (1-indexed), representing the row and column of the person whose state is toggled.
All input is given via standard input.
outputFormat
For each toggle command, output a single integer on a new line — the total number of visible pairs of standing people in the grid after performing that toggle.
Output should be written to standard output.
## sample4 4
SSSS
STTT
SSSS
STSS
3
2 2
3 4
4 2
3
2
3
</p>