Grid Query
Time limit4sMemory limit1024 MB
Process N rectangle-add updates and Q rectangle-sum queries on a sparse 200000 by 200000 grid, then XOR all query answers.
- Level
Medium7 of 10
- Topics
- Prefix sum, Matrix, Implementation, Sorting
- Solved
- No attempts yet
Problem
There is a two-dimensional array of size 200000 by 200000, filled entirely with zeros. In this array, row numbers increase downward and column numbers increase to the right. The position at row i, column j is written as (i,j).
To watch everyone suffer, Jongyeong performed an update operation N times, each adding V to the value at every position between (X1,Y1) and (X2,Y2).
You must process Q queries, each asking for the sum of the values at every position between (X1,Y1) and (X2,Y2).
Input
The first line gives N and Q. (1 ≤ N, Q ≤ 2.5×105)
Over the next N lines, X1, Y1, X2, Y2, V for Jongyeong's updates are given in order. (1 ≤ X1 ≤ X2 ≤ 2×105, 1 ≤ Y1 ≤ Y2 ≤ 2×105, 1 ≤ V ≤ 10)
Over the next Q lines, X1, Y1, X2, Y2 for the queries are given in order. (1 ≤ X1 ≤ X2 ≤ 2×105, 1 ≤ Y1 ≤ Y2 ≤ 2×105)
Output
Print one value: the XOR of the answers to all queries. In C and C++ this is expressed with the ^ operator. The meaning of the XOR operator has nothing to do with solving this problem.