Gophers
Time limit3sMemory limit128 MB
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 gopher holes in a row, indexed to from west to east. Hole sits at the origin (distance ), and hole (for ) sits meters east of hole , with .
Dick placed CD players along the ridge; player sits meters east of hole . Each player disturbs every hole within meters of it: a hole at distance from hole is disturbed by a player at distance whenever . A hole's gopher cannot sleep if at least one CD player disturbs that hole.
Over days the players are rearranged. On the morning of day , Dick moves the player currently located meters from hole to a point meters from hole . Immediately before each move, position holds exactly one player and position holds none.
Report the number of holes whose gophers cannot sleep at the required moments.
Input
The first line contains four integers , , , (, , ): the number of holes, the number of CD players, the number of days, and each player's range.
The second line contains integers (): the distances of holes from hole .
The third line contains integers (): the distances of the CD players from hole ; every player lies east of hole .
Each of the next lines contains two integers and (, ): on day the player at distance is moved to distance . Immediately before each move a player is guaranteed to be at position and no player is at position .
Output
Output lines. For , line must contain the number of sleepless holes in the state just before the -th move. Line 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 moves in order, print the new count.)