cswork / OA打开练习工作台

UberOA #31

Counting Segments After House Removals

估计中等可在线判题

考点(AI 标注)哈希计数

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.

输入格式

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⁹.

输出格式

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

样例 1

输入:

6 3
1 2 3 6 7 9
2 6 9

输出:

4
4
3

样例 2

输入:

5 3
1 5 6 8 10
5 8 10

输出:

4
3
2

样例 3

输入:

1 1
1
1

输出:

0

样例说明

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.