2D Array Range Add and Range Sum
InterviewTime limit3sMemory limit512 MB
Given an n by n matrix, apply all rectangle add updates in order, then print the sum of each rectangle query.
- Level
Medium4 of 10
- Topics
- Matrix, Prefix sum
- Solved
- No attempts yet
Problem
You are given an integer 2D array of size . The elements are . The initial values of all elements are given as input. Array stores queries on , and each query is one of two types. Type 1 is the first kind, and type 2 is the second kind.
- 1 : Add to every with and .
- 2 : Output the sum of every with and .
Process the queries in from the first to the -th in order, and output the results of the type 2 queries. All type 1 queries are stored before all type 2 queries in .
Input
The first line contains and , separated by a space. The next lines contain the elements of . The -th number on the -th line is . The next lines each contain one query, given in order. The numbers in each line are separated by spaces.
Output
Print the results of the type 2 queries in order, one per line.
Constraints
- ,
- ()
- contains only type 1 and type 2 queries.
- All type 1 queries are stored before all type 2 queries in .
- contains at least one type 2 query.