Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Update submatrix and query submatrix.

$
0
0

If we are given a matrix of NxN (N<=1000). There are 2 operations:

  1. update x1, y1, x2, y2, val. In this operation, val is added to each element in the sub-matrix (x1, y1, x2 y2).
  2. Query x1, y1, x2, y2. In this operation, the sum of all the elements in the sub-matrix (x1, y1, x2, y2).

How do I perform them efficiently? I tried coding some sort of a 2-d segment tree but that doesn't work. Quadtree cant be used as it is O(N) in worst case.


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>