QOJ.ac

QOJ

时间限制: 30.0 s 内存限制: 256 MB 总分: 100

#17368. Skyscrapers

统计

在一个海滨村庄里,有一条由摩天大楼组成的街道。每栋摩天大楼宽 $100\text{ m}$,并具有一定的高度。由于地价非常昂贵,任意两栋相邻的摩天大楼都是紧挨着的。这条街道紧邻沙滩,因此街道地面恰好处于海平面高度。

不幸的是,今年由于全球变暖,海平面开始每天上升一米。如果某栋摩天大楼的高度不大于当前的海平面高度,则认为它被淹没了。

一个“区域”是指极大未被淹没且相邻的摩天大楼集合。这个概念尤为重要,因为只需向每个区域中的任意一栋摩天大楼运送物资(如电流、胡萝卜或卷心菜)即可。因此,市长想要知道在接下来的艰难日子里,每天会有多少个区域。

下图给出了一个包含 5 栋摩天大楼在第 2 天时的示例。

输入格式

输入包含多组测试数据。第一行包含一个整数 $t$ ($t \le 15$),表示测试数据的组数。接下来是 $t$ 组测试数据。

每组测试数据的第一行包含两个整数 $n$ 和 $d$ ($1 \le n, d \le 10^6$),其中 $n$ 是摩天大楼的数量,$d$ 是市长想要查询的天数。摩天大楼从左到右依次编号。

第二行包含 $n$ 个整数 $h_1, h_2, \dots, h_n$,其中 $1 \le h_i \le 10^9$ 表示第 $i$ 栋摩天大楼的高度。

第三行包含 $d$ 个整数 $t_j$,满足 $0 \le t_1 < t_2 < \dots < t_{d-1} < t_d \le 10^9$。

输出格式

对于每组测试数据,输出 $d$ 个整数 $r_1, r_2, \dots, r_d$,其中 $r_j$ 表示在第 $t_j$ 天时的区域数量。

样例

输入样例 1

2
3 3
1 2 3
1 2 3
5 3
1 3 5 1 3
0 2 4

输出样例 1

1 1 0
1 2 1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.