Moving people

3.6

11 votes
Problem

Updated problem name

Moving people

Updated problem statement

The people of your city are living in a  x  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  operations or query of the following types:

  • : Move every person that is currently residing in the grid,  column left of their cells and  column above of their cells. If  is negetive, then move people  column right of their cells. Also, if  is negative, then move people  column down of their cells.
  • : Calculate the numbner of people that are currently living in the grid.

Input format

  • First line: Three integers,  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 . In the  string, the  character is  if there is a person in that cell, otherwise there will be 
  • Next  lines: One of the  types of operations as stated above. 

Output format
For each  type of query, print the number of persons that are available in the grid at the time of that query.

Constraints



Sample Input
4 4 6
1111
0001
1101
0011
2
1 0 -2
1 1 0
2
1 -2 1
2
Sample Output
10
4
2
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

After update operation, the grid will look like this:






After the  update operation, the grid will look like this:






After the  update operation, the grid will look like this:




Editor Image

?