Given N, М and K. All nubers are < = 109
Define value of matrix in row i and column j as (i + j) mod K where i < = N and j < = M
Given Q < = 2 * 105 queries of form Li, Lj, Ri, Rj and you need to find sum of elements in submatrix with upper left corner (Li, Lj) and lower right corner (Ri, Rj) module 109 + 7.
Some ideas?