Dancing Elephants is a spectacular show in Pattaya that features
After years of training, elephants in this show are capable of many amazing dances. The show consists of a series of acts. In each act, exactly one elephant performs a cute dance while possibly moving to a different position.
The show producers want to produce a photo book that contains pictures of the entire show. After each act, they want to take pictures of all elephants as seen by the spectators.
At any time during the show, multiple elephants may share the same position. In that case, they simply stand behind one another at the same position.
A single camera can take a picture of a group of elephants if and only if all their positions lie on some segment of length
As an example, suppose that
In the following act, the elephant at position
In the next act, the elephant at position
In this task, you have to determine the minimum number of cameras needed to take the pictures after each of the acts. Note that the number of cameras needed may increase, decrease, or stay the same between acts.
Your task
Write a program that takes the following parameters initially:
– the number of elephants. The elephants are numbered through . – the length of the segment captured by a single camera. You may assume that is an integer such that . – a one-dimensional array of integers representing the initial positions of the elephants. For , elephant starts at the position . The initial positions are in sorted order. More precisely, you may assume that . Note that during the dance the elephants may reorder themselves.
Then, there will be
– the number of the elephant that moves in the current act. – the position where the elephant will stand after the current act. You may assume that is an integer such that .
This procedure will be called multiple times. Each call corresponds to a single act (which follows on from all of the previous acts). Each call must return the minimum number of cameras needed to photograph all elephants after the corresponding act.
Example
Consider the case where
First, input will be consist of these parameters. Afterwards, there will be
act | call parameters | output value |
---|---|---|
1 | update(2,16) | 1 |
2 | update(1,25) | 2 |
3 | update(3,35) | 2 |
4 | update(0,38) | 2 |
5 | update(2,0) | 3 |
Input Specification
- Line
: , , and - Lines
to : the initial positions; i.e., line contains for . - Lines
to : information on acts; i.e. line contains and , separated by a space, denoting that in the act elephant moves to position , for .
Output Specification
Lines
Sample Input
4 10 5
10
15
17
20
2 16
1 25
3 35
0 38
2 0
Sample Output
1
2
2
2
3
Subtasks
Subtask 1 (10 points)
- There are exactly
elephants. - Initially, and after each act, the positions of all elephants will be distinct.
- Your procedure update will be called at most
times.
Subtask 2 (16 points)
.- Initially, and after each act, the positions of all elephants will be distinct.
- Your procedure update will be called at most
times.
Subtask 3 (24 points)
.- Initially, and after each act, the positions of all elephants will be distinct.
- Your procedure update will be called at most
times.
Subtask 4 (47 points)
.- Elephants may share the same position.
- Your procedure update will be called at most
times.
Subtask 5 (3 points)
.- Elephants may share the same position.
- Your procedure update will be called at most
times. - Note: The collection templates in the C++ Standard Library (STL) can be slow; in particular, it might not be possible to solve subtask 5 if you use them.
Comments