cswork / OAOpen practice workspace

UberOA #31

Counting Segments After House Removals

Estimated MediumJudge-ready

Topics (AI-labelled)Hashing

Distinct houses sit at integer coordinates, and houses whose coordinates differ by 1 are connected. Demolish the given houses one by one and, after each step, output the number of remaining contiguous blocks. A valid query guarantees that the house to be demolished still exists. The intermediate counts in both examples on the original site conflict with the definition of contiguity and have been corrected according to the statement.

This site has made the standard input and output explicit.

Input

The first line contains n q, the second line contains n coordinates, and the third line contains the q coordinates to demolish. 1≤q≤n≤100000; the source gives no bound on coordinates, so on this site coordinates are in −10⁹..10⁹.

Output

After each demolition, output one line with the number of blocks.

Example 1

Input:

6 3
1 2 3 6 7 9
2 6 9

Output:

4
4
3

Example 2

Input:

5 3
1 5 6 8 10
5 8 10

Output:

4
3
2

Example 3

Input:

1 1
1
1

Output:

0

Example notes

Example 1: after demolishing 2, 6 and 9 in turn, the blocks are {1},{3},{6,7},{9}, 4 in total; then {1},{3},{7},{9}, 4 in total; finally 3. Example 2: after demolishing 5, the remaining blocks are 1, 6, 8, 10, 4 in total; then 3 and 2. The original site's 3, 3, 2 does not match the definition. Example 3: after the last house is demolished, there are 0 blocks.

Editorial

Loading solution…