Unseen Segments

두 관찰자의 시력 세기가 주어질 때마다 어느 쪽도 보지 못하는 부분의 전체 길이를 구한다.

어려움8기하정렬누적 합이분 탐색아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

Consider a two-dimensional grid with nn vertical segments on it. There are two observers, one on the west and one on the east, standing at points on the X axis which are infinitely far from the segments.

Each observer has an x-ray vision of some non-negative integer power that allows him to look through segments. A point of a segment can be seen with vision of power pp if there are no more than pp other segments crossing the straight line between the observer and this point. We say that a part of a segment is invisible if it is not seen by any of the observers.

You are given qq queries. Each query contains two integers: the power of vision of the west and the east observer, respectively. For each query, you need to determine the total length of the invisible parts over all segments.

입력

The first line contains one integer nn (1n1051 \le n \le 10^5), the number of segments.

The ii-th of the following nn lines contains three integers x_ix\_i, a_ia\_i, and b_ib\_i (1x1091 \le x \le 10^9, 1a_i<b_i1091 \le a\_i < b\_i \le 10^9), which describe placement of the ii-th segment: its endpoints have coordinates (x_i,a_i)(x\_i, a\_i) and (x_i,b_i)(x\_i, b\_i). It is guaranteed that each segment has positive length and no two segments share a common point.

The next line contains one integer qq (1q1051 \le q \le 10^5), the number of queries.

Each of the following qq lines contains two integers ll and rr (0lr1050 \le l \le r \le 10^5), the power of vision of the west and the east observer in this query, respectively.

출력

Output qq lines, one integer per line: the answers for the corresponding queries.

힌트

In the first query, the western observer fully sees the first segment, the part of the fourth segment at Y-coordinates \[5,6]\[5, 6], and the part of the sixth one at Y-coordinates \[6,7]\[6, 7].

The eastern observer fully sees the fifth and the sixth segments, the part of the fourth segment at Y-coordinates \[2,3]\[2, 3], and the part of the third one at Y-coordinates \[1,2]\[1, 2].

The parts that remain invisible: the complete second segment, the part of the third one at Y-coordinates \[2,3]\[2, 3], and the part of the fourth one at Y-coordinates \[3,5]\[3, 5]. Their total length is 1+1+2=41 + 1 + 2 = 4.

In all other queries, there are no invisible parts.