Catching Water Bottles
Time limit2sMemory limit256 MB
Given N bottles with thresholds D_i, count how many bottles plus Jaehyeok lie within [L, R] at time T as the bottles trail him each second.
- Level
Hard8 of 10
- Topics
- Segment tree, Simulation, Array
- Solved
- No attempts yet
Problem
Jaehyeok has an unusual hobby. At time , he tastes the water of every bottle whose position is between and , inclusive. But he had been sitting still and drinking water in place, and he worried about becoming obese, so he decided to move. The bottles are free-spirited and move when a certain condition holds.
The bottles are numbered , and the initial position of bottle is . Jaehyeok starts at . Every second, Jaehyeok and the bottles move according to these rules.
- Jaehyeok moves to the right every second.
- Bottles do not move carelessly, since the water might spill. After Jaehyeok moves, bottle moves to (Jaehyeok's position) if its distance from Jaehyeok is at least .
- After bottle 's position is decided, bottle moves to (bottle 's position) if its distance from bottle is at least . Bottles move in the same way, in order. That is, bottle moves to (bottle 's position) if its distance from bottle is at least .
Jaehyeok drank so much water that he began to wonder how many bottles he can catch, given , , and . He had also started to think he was a bottle himself. So if Jaehyeok's position is between and inclusive, add to the answer.
Input
The first line contains the number of bottles () and the number of queries (). The next lines each contain (). The next lines each contain , , and (, ).
Output
Print lines. On line , print how many bottles are between and inclusive at time .