Elephants

Time limit12sMemory limit256 MB

Summary
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 NN elephants stand in a row on a stage and dance. The elephants are numbered from 00 to N−1N-1.

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 LL (both endpoints included): a camera placed at position ss captures every elephant in the interval [s, s+L][s,\ s+L]. 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 L=10L=10 and the elephants are at positions 10,15,17,2010, 15, 17, 20, 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 1515 walks to 3232, then at least two cameras are needed to capture this moment.

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

The camera segment length LL is an integer with 0≤L≤1090 \le L \le 10^9. The initial position X[i]X[i] of elephant ii is an integer, and the positions are given sorted: 0≤X[0]≤X[1]≤⋯≤X[N−1]≤1090 \le X[0] \le X[1] \le \cdots \le X[N-1] \le 10^9. As moves are performed, the sorted order of the positions may change. Each move is given by an elephant index ii and a new position yy (0≤y≤1090 \le y \le 10^9), and it changes the position of elephant ii to yy.

Input

The first line contains the number of elephants NN, the camera segment length LL, and the number of moves MM, separated by spaces.

Each of the next NN lines contains one initial position, one per line. The ii-th of these values is X[i−1]X[i-1], and they are given in non-decreasing order.

Each of the following MM lines describes one move: two integers ii and yy separated by a space, meaning elephant ii moves to position yy.

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.

Examples2

  1. Example 1

    Input
    4 10 5
    10
    15
    17
    20
    2 16
    1 25
    3 35
    0 38
    2 0
    
    Expected output
    1
    2
    2
    2
    3
    
  2. Example 2

    Input
    3 0 4
    5
    5
    8
    0 8
    1 8
    2 10
    0 10
    
    Expected output
    2
    1
    2
    2