Grid and Queries
Time limit2sMemory limit1024 MB
Starting from an N by N grid of zeros, the task applies queries that set a whole row or column to a value and prints the sum of a given row or column.
- Level
Medium6 of 10
- Topics
- Segment tree, Implementation
- Solved
- No attempts yet
Problem
An grid is given. Each cell holds one number, and initially every cell contains . Process the following queries.
1 i v: Change every number in row to .2 i v: Change every number in column to .3 i: Print the sum of all numbers in row .4 i: Print the sum of all numbers in column .
It is guaranteed that there is at least one 3 i or 4 i query.
Input
The first line contains the grid size and the number of queries .
Each of the next lines contains one query.
Output
For each 3 i and 4 i query, print the sum of the corresponding row or column on its own line, in the order the queries are given.