| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3.5 초 (추가 시간 없음) | 1024 MB | 72 | 12 | 9 | 15.517% |
There are $R$ runners about to participate in a marathon. Johnny, who is organizing the marathon, knows that if a runner starts to run at time $T$ with constant speed $S,ドル then at time $t$ (for $t ≥ T$) the runner will be at position $(t - T) \times S$ on the track. Before time $T,ドル the runner is considered to not be on the track.
Of course, such an event has to have great photos taken. $P$ photos will be taken in total. Each photo will be taken at a specific time and will contain a carefully chosen segment of the track. If there are no runners in that segment at that time, the photo is considered to be trash.
Johnny, knowing all this, was saddened by the number of trash photos that would come from his event, so he decided to take the matter into his own feet and participate in the marathon along with the other runners.
Johnny is considering how he may run, so he will ask you $Q$ queries of the following format: if Johnny starts to run at a given time with a certain constant speed, how many trash photos will still be taken in his event?
The first line contains an integer $R$ (1ドル ≤ R ≤ 1000$) indicating the number of runners. Each of the next $R$ lines describes a runner with two integers $T$ (0ドル ≤ T ≤ 10^9$) and $S$ (1ドル ≤ S ≤ 10^9$), representing respectively the starting time and the speed of the runner.
The next line contains an integer $P$ (1ドル ≤ P ≤ 10^6$) denoting the number of photos. Each of the next $P$ lines describes a photo with three integers $U$ (0ドル ≤ U ≤ 10^9$), $A$ and $B$ (0ドル ≤ A ≤ B ≤ 10^9$), specifying that the photo will be taken at time $U$ and will cover the segment $[A, B]$ of the track.
The next line contains an integer $Q$ (1ドル ≤ Q ≤ 1000$) indicating the number of queries. Each of the next $Q$ lines describes a query with two integers $T'$ (0ドル ≤ T' ≤ 10^9$) and $S'$ (1ドル ≤ S' ≤ 10^9$), representing respectively a possible starting time and speed for Johnny.
Output $Q$ lines, each line with an integer indicating the number of trash photos for the corresponding query of the input.
3 0 1 2 2 4 2 3 1 2 4 5 8 16 3 1 8 3 3 1 1 3 0 2
2 1 0