City Influence
Time limit2sMemory limit64 MB
Add N weighted rectangles on a billion by billion grid and print the sum of squared cell values modulo 1,000,000,007.
- Level
Medium7 of 10
- Topics
- Segment tree, Sorting, Prefix sum
- Solved
- No attempts yet
Problem
A new city is being built. Seen from above the city is a plane, and that plane is cut into cells of equal size. The top left cell is and the bottom right cell is . Every cell carries a number that records the influence on that cell, and every number starts at .
The city will contain many public facilities, so before construction the planners estimated the influence each facility spreads around it. One estimate has this form.
- Add to every cell with and .
After all estimates are applied, the influence of one cell is the square of the number written on it, and the influence of the city is the sum of the influence of all cells.
Suppose there are these two estimates.
- Add to every cell with and .
- Add to every cell with and .
Cells and then hold , cells , , , hold , cells and hold , and every other cell holds . The influence of the city is .

Given estimates, write a program that computes the influence of the city after all of them are applied.
Input
The first line contains the number of estimates ().
Each of the next lines contains , , , , (, , ) separated by spaces. Each line is one estimate as described above.
Output
Print the influence of the city after all estimates are applied. The answer can be very large, so print it modulo 1,000,000,007.