For each new axis-aligned rectangle, compute the total area of the given union of rectangles that it covers.
Hard9Segment treePrefix sumGeometrySortingNo attempts yetTime limit2sMemory limit1024 MBMirek is a devoted fan of one music band. He goes to every concert and collects a poster each time. Whenever he gets a new poster, he hangs it on the wall above his bed. After many years of collecting, the wall is almost full and Mirek can no longer find room for new posters. He just got a few more of them and wants to pick a spot on the wall for each one. To pick a spot he needs to know how much of the other posters it would cover.
You are given the coordinates of the posters that already hang on the wall, and the coordinates of the posters that Mirek is thinking of hanging. For each new poster, compute the area of the hanging posters that this poster would cover directly.
The posters on the wall may overlap each other. When an overlapping part is covered, its area counts only once.
The new posters are judged independently. While you compute the answer for one new poster, the other new posters are not on the wall.
The first line contains the number of posters that hang on the wall, N (1≤N≤100000). Each of the next N lines describes one of them. Line N+2 contains the number of new posters Mirek would like to hang, M (1≤M≤100000), and each of the next M lines describes one of them.
Every poster is a rectangle with sides parallel to the axes, described by four integers x1, y1, x2, y2 (0≤x1<x2≤109, 0≤y1<y2≤109). (x1,y1) is the bottom left corner and (x2,y2) is the top right corner.
For each new poster print one line with one integer, the area of the hanging posters that this poster covers. Print the answers in the order the new posters are given.
The picture below shows Mirek's wall. Dashed rectangles are the new posters, and filled rectangles are the posters that already hang.
