Elephants
Time limit12sMemory limit256 MB
After each of M moves that relocate one elephant, report the minimum number of length-L segments needed to cover all current positions.
- Level
Hard8 of 10
- Topics
- Segment tree, Dynamic programming, Sorting, Binary search
- Solved
- No attempts yet
Problem
You are filming an elephant show in which elephants stand in a row on a stage and dance. The elephants are numbered from to .
The show consists of a sequence of moves. In each move, exactly one elephant walks to a different position on the stage (it may also stay where it is). Several elephants may share the same position; in that case they simply stand one behind another.
Right after each move, you want to photograph every elephant on the stage at that moment. A single camera can only photograph the elephants lying within a segment of length (both endpoints included): a camera placed at position captures every elephant in the interval . When the elephants are spread out, several cameras may be needed to capture everyone at once.
After each move, determine the minimum number of cameras needed to photograph all elephants at that moment. This number may increase, decrease, or stay the same from one move to the next.
For example, if and the elephants are at positions , then, as shown below, a single camera captures all of them. (Triangles are elephants; the trapezoid is a camera.)

If, in the next move, the elephant at position walks to , then at least two cameras are needed to capture this moment.

If, in the following move, the elephant at position walks to , then three cameras are needed to photograph all elephants.

The camera segment length is an integer with . The initial position of elephant is an integer, and the positions are given sorted: . As moves are performed, the sorted order of the positions may change. Each move is given by an elephant index and a new position (), and it changes the position of elephant to .
Input
The first line contains the number of elephants , the camera segment length , and the number of moves , separated by spaces.
Each of the next lines contains one initial position, one per line. The -th of these values is , and they are given in non-decreasing order.
Each of the following lines describes one move: two integers and separated by a space, meaning elephant moves to position .
Output
For each move, output on its own line the minimum number of cameras needed to photograph all elephants after that move, in the order the moves are given in the input.