PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000053. Điệu nhảy của những chú voi (Dancing Elephants)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Điệu nhảy của những chú voi (Dancing Elephants)

Dancing Elephants

Source: IOI

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn elephants on a number line, with fixed elephant IDs from 00 to n−1n-1 and initially sorted positions X0≤⋯≤Xn−1X_0\le\cdots\le X_{n-1}. A camera covers elephants in any closed interval of length at most LL. After each move, find the minimum number of cameras needed to photograph all elephants.

An operation i y moves the elephant with fixed ID ii to coordinate yy. Elephants may change their order and can occupy equal coordinates. Cameras may be repositioned after every move.

This adaptation converts the IOI init/update grader interface to standard input/output: one answer line for each update. No hidden expected-answer field s[j] is supplied in the input.

Input

The first line contains n,L,mn,L,m. The next nn lines specify the initially nondecreasing elephant positions X0,…,Xn−1X_0,\ldots,X_{n-1}. Each of the final mm lines contains i y, where elephant ID ii (zero-indexed) moves to position yy. All positions and LL lie in [0,109][0,10^9].

Output

After every move, output the minimum number of cameras on a separate line.

Subtasks

  • Subtask 1 (10 points): 1≤n≤21\le n\le 2; 1≤m≤1001\le m\le 100; Exactly two elephants; all current positions remain distinct.
  • Subtask 2 (16 points): 1≤n≤1001\le n\le 100; 1≤m≤1001\le m\le 100; All current elephant positions remain pairwise distinct after every move.
  • Subtask 3 (24 points): 1≤n≤500001\le n\le 50000; 1≤m≤500001\le m\le 50000; All current elephant positions remain pairwise distinct after every move.
  • Subtask 4 (47 points): 1≤n≤700001\le n\le 70000; 1≤m≤700001\le m\le 70000; Multiple elephants may share the same position.
  • Subtask 5 (3 points): 1≤n≤1500001\le n\le 150000; 1≤m≤1500001\le m\le 150000; No additional restriction; coincident positions are allowed.

Examples

Input

4 10 5
10
15
17
20
2 16
1 25
3 35
0 38
2 0

Output

1
2
2
2
3

Explanation

Initially all four positions 10,15,17,2010,15,17,20 fit in a length-1010 interval. Moving elephant ID 2 to 1616 still needs one camera; moving ID 1 to 2525 needs two. The remaining three updates yield 2, 2, and 3 cameras respectively.