Updated problem name
Moving people
Updated problem statement
The people of your city are living in a \(N\) x \(M\) grid. If a person is out of the grid after multiple instructions, then that person is not counted in further steps.
Initially, there is at most one person in every cell of this grid. You can perform \(Q\) operations or query of the following types:
- \(1\ X\ Y\): Move every person that is currently residing in the grid, \(X\) column left of their cells and \(Y\) column above of their cells. If \(X\) is negetive, then move people \(abs(X)\) column right of their cells. Also, if \(Y\) is negative, then move people \(abs(Y)\) column down of their cells.
- \(2\): Calculate the numbner of people that are currently living in the grid.
Input format
- First line: Three integers, \(N, M,\ and\ Q\) denoting the number of rows that are available in the grid, number of columns that are available in the grid, and number of instructions
- Next N lines: A string consisting of only \(0\ and\ 1\). In the \(i^{th}\) string, the \(j^{th}\) character is \(1\) if there is a person in that cell, otherwise there will be \(0\)
- Next \(Q\) lines: One of the \(2\) types of operations as stated above. \(\)
Output format
For each \(2^{nd}\) type of query, print the number of persons that are available in the grid at the time of that query.
Constraints
\(1 \leq N, M \leq 10^3\)
\(1 \leq Q \leq 10^5\)
\(-1000 \leq X, Y \leq 1000\)
After \(1^{st}\)update operation, the grid will look like this:
\(0000\)
\(0000\)
\(1111\)
\(0001\)
After the \(2^{nd}\) update operation, the grid will look like this:
\(0000\)
\(0000\)
\(1110\)
\(0010\)
After the \(3^{rd}\) update operation, the grid will look like this:
\(0000\)
\(0011\)
\(0000\)
\(0000\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor