This page is still under construction.

Parts of this page are still being built. What you see may change.

Gophers

Time limit3sMemory limit128 MB

Summary
Given gopher holes and CD players on a line, count holes covered by at least one player before and after each of d moves of a player, outputting d+1 counts.
Level

Medium7 of 10

Topics
Sorting, Binary search, Intervals, Implementation
Solved
No attempts yet

Problem

Dick Dastardly wants to torment the gophers living along a straight mountain ridge. The ridge has nn gopher holes in a row, indexed 11 to nn from west to east. Hole 11 sits at the origin (distance 00), and hole ii (for 2≤i≤n2 \le i \le n) sits xix_i meters east of hole 11, with x2<x3<⋯<xnx_2 < x_3 < \cdots < x_n.

Dick placed mm CD players along the ridge; player jj sits zjz_j meters east of hole 11. Each player disturbs every hole within ll meters of it: a hole at distance pp from hole 11 is disturbed by a player at distance zz whenever ∣p−z∣≤l|p - z| \le l. A hole's gopher cannot sleep if at least one CD player disturbs that hole.

Over dd days the players are rearranged. On the morning of day ii, Dick moves the player currently located pip_i meters from hole 11 to a point rir_i meters from hole 11. Immediately before each move, position pip_i holds exactly one player and position rir_i holds none.

Report the number of holes whose gophers cannot sleep at the required moments.

Input

The first line contains four integers nn, mm, dd, ll (2≤n,m≤5000002 \le n, m \le 500000, 1≤d≤5000001 \le d \le 500000, 1≤l≤1091 \le l \le 10^9): the number of holes, the number of CD players, the number of days, and each player's range.

The second line contains n−1n-1 integers x2,x3,…,xnx_2, x_3, \ldots, x_n (0<x2<x3<⋯<xn≤1090 < x_2 < x_3 < \cdots < x_n \le 10^9): the distances of holes 2,3,…,n2, 3, \ldots, n from hole 11.

The third line contains mm integers z1,z2,…,zmz_1, z_2, \ldots, z_m (0≤z1<z2<⋯<zm≤1090 \le z_1 < z_2 < \cdots < z_m \le 10^9): the distances of the CD players from hole 11; every player lies east of hole 11.

Each of the next dd lines contains two integers pip_i and rir_i (0≤pi,ri≤1090 \le p_i, r_i \le 10^9, pi≠rip_i \ne r_i): on day ii the player at distance pip_i is moved to distance rir_i. Immediately before each move a player is guaranteed to be at position pip_i and no player is at position rir_i.

Output

Output d+1d + 1 lines. For i=1,2,…,di = 1, 2, \ldots, d, line ii must contain the number of sleepless holes in the state just before the ii-th move. Line d+1d + 1 must contain the number of sleepless holes after the last move.

(Equivalently: print the count for the initial arrangement, then, after applying each of the dd moves in order, print the new count.)

Examples3

  1. Example 1

    Input
    5 3 4 1
    2 5 6 11
    2 4 8
    2 1
    4 10
    8 6
    1 8
    
    Expected output
    2
    3
    3
    5
    3
    
  2. Example 2

    Input
    2 1 2 3
    10
    5
    5 10
    10 0
    
    Expected output
    0
    1
    1
    
  3. Example 3

    Input
    4 2 2 1000000000
    100 200 1000000000
    0 500000000
    0 1000000000
    500000000 1
    
    Expected output
    4
    4
    4