「ROIR 2023 Day2」石头
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
题目描述
在鲍勃面前有一排 块黑色石头,编号从 到 。第 块石头上写着一个整数 。对于每个从 到 的数字,恰好有一个石头上写着这个数字,换句话说,数字 形成了一个排列。我们称第 块石头的相邻石头为 和 (如果它们存在)。
鲍勃执行以下 个步骤:
- 第一步,鲍勃从 到 中选择一个任意的 ,并将第 块石头涂成白色。
- 从第 步到第 步,鲍勃查看所有至少有一个相邻白色石头的黑色石头,从中选择 最小的石头 ,并将其涂成白色。
很容易看出,执行完所有步骤后,鲍勃面前将有 块白色石头。
爱丽丝选择了 对值 和 。对于每对值,她想知道有多少种不同的方法可以选择第一步的石头,使得编号为 的石头恰好在第 步被涂成白色。
请帮助鲍勃回答爱丽丝的 个查询。
输入格式
第一行输入包含两个整数 和 ,分别表示石头的数量和查询的数量。
第二行输入包含 个整数 (,所有 都不同)。
接下来的 行中,每行包含一对整数 和 ,表示石头的编号和该石头在第 步被涂成白色。
输出格式
对于每个查询,输出一个整数,表示如果第 块石头在第一步被涂成白色,那么编号为 的石头在第 步被涂成白色的不同方法的数量。
6 4
1 4 6 5 2 3
3 1
2 2
6 3
4 3
1
2
1
2
在第一个样例中,操作如下:
- 如果第一步选择第 块石头:第 步:,第 步:,第 步:,第 步:$[\mathbf{1}, \mathbf{4}, \mathbf{6}, \mathbf{5}, 2,3]$,第 步:$[\mathbf{1}, \mathbf{4}, \mathbf{6}, \mathbf{5}, \mathbf{2}, 3]$,第 步:$[\mathbf{1},\mathbf{4},\mathbf{6},\mathbf{5},\mathbf{2},\mathbf{3}]$。
- 如果第一步选择第 块石头:第 步:,第 步:,第 步:,第 步:$[\mathbf{1}, \mathbf{4},\mathbf{6},\mathbf{5},\mathbf{2},\mathbf{3}]$,第 步:$[\mathbf{1}, \mathbf{4}, \mathbf{6}, \mathbf{5}, \mathbf{2}, 3]$,第 步:$[\mathbf{1},\mathbf{4},\mathbf{6},\mathbf{5},\mathbf{2},\mathbf{3}]$。
- 如果第一步选择第 块石头:第 步:,第 步:,第 步:,第 步:$[\mathbf{1}, \mathbf{4},\mathbf{6},\mathbf{5},\mathbf{2},\mathbf{3}]$,第 步:$[\mathbf{1}, \mathbf{4}, \mathbf{6}, \mathbf{5}, \mathbf{2}, 3]$,第 步:$[\mathbf{1},\mathbf{4},\mathbf{6},\mathbf{5},\mathbf{2},\mathbf{3}]$。
- 如果第一步选择第 块石头:第 步:,第 步:,第 步:,第 步:$[1,4, \mathbf{6}, \mathbf{5}, \mathbf{2}, \mathbf{3}]$,第 步:$[1, \mathbf{4}, \mathbf{6}, \mathbf{5}, \mathbf{2}, \mathbf{3}]$,第 步:$[\mathbf{1},\mathbf{4},\mathbf{6},\mathbf{5},\mathbf{2},\mathbf{3}]$。
- 如果第一步选择第 块石头:第 步:,第 步:,第 步:,第 步:$[1,4, \mathbf{6}, \mathbf{5}, \mathbf{2}, \mathbf{3}]$,第 步:$[1, \mathbf{4}, \mathbf{6}, \mathbf{5}, \mathbf{2}, \mathbf{3}]$,第 步:。
- 如果第一步选择第 块石头:第 步:,第 步:,第 步:,第 步:$[1,4, \mathbf{6}, \mathbf{5}, \mathbf{2}, \mathbf{3}]$,第 步:$[1, \mathbf{4}, \mathbf{6}, \mathbf{5}, \mathbf{2}, \mathbf{3}]$,第 步:$[\mathbf{1},\mathbf{4},\mathbf{6},\mathbf{5},\mathbf{2},\mathbf{3}]$。
5 3
5 2 3 4 1
2 3
4 4
3 2
0
1
1
数据范围与提示
详细子任务附加限制及分值如下表所示。
子任务 | 分值 | 附加限制 | 子任务依赖 |
---|---|---|---|
递增 | |||
所有 相同 | |||
所有 相同 | |||
无附加限制 |
NOIP模拟赛
- Status
- Done
- Rule
- OI
- Problem
- 4
- Start at
- 2024-10-25 8:00
- End at
- 2024-10-25 12:00
- Duration
- 4 hour(s)
- Host
- Partic.
- 48