Infection Simulation
Time limit1.5sMemory limit1024 MB
Given N customer stay intervals, each query asks how many customers end up infected from a given patient zero when the infection resistance is X.
- Level
Hard8 of 10
- Topics
- Intervals, Graph, Dynamic programming, Binary search
- Solved
- No attempts yet
Problem
EGOI cafeteria had customers yesterday. Customers are numbered from to . Customer () entered at time and left at time . Today it was found that one customer came in already infected with the new strain of disease X that is currently spreading in JOI Country.
The infection resistance of disease X is an integer . Specifically, for each , customer becomes a new infected person as soon as the total time customer spends in the cafeteria together with at least one infected person reaches or more.
JOI Country enforces strict infection control, so the number of infected people must be tracked accurately. However, no one knows who was infected with disease X, and the value of is unknown.
Ms. Rie, the manager of the EGOI cafeteria, wants the final number of infected customers for each of scenarios. In the -th scenario (), customer is the only initial infected person, and the infection resistance of disease X is .
Given the customer and scenario information, write a program that prints the final number of infected customers for each scenario. A customer infected at exactly their leave time is counted. A customer who has become infected never stops being infected.
Input
The input is given in the following format.
N
L1 R1
L2 R2
︙
LN RN
Q
P1 X1
P2 X2
︙
PQ XQ
Output
Print lines. On line (), print the final number of infected customers in the -th scenario.
Constraints
- .
- ().
- .
- ().
- ().
- All input values are integers.