QOJ.ac

QOJ

時間限制: 30 s 記憶體限制: 1024 MB 總分: 42

#11459. 公平竞争

统计

准备好!Charles 和 Delila 即将在“剑术大师”击剑锦标赛的决赛中对决。

在击剑竞技场的一面墙上,有一个架子,上面放着 $N$ 种不同类型的剑;剑的类型编号从 $1$ 到 $N$。作为主裁判,你将选择一对整数 $(L, R)$(满足 $1 \le L \le R \le N$),只有第 $L$ 到第 $R$ 种(包含 $L$ 和 $R$)剑可供比赛使用。

不同类型的剑使用方式不同,擅长某种剑并不意味着擅长另一种!Charles 和 Delila 对第 $i$ 种剑的熟练度分别为 $C_i$ 和 $D_i$。他们每个人都会查看你为这场比赛提供的剑的类型,然后各自选择一种他们最擅长的剑。如果对于某位选手,有多种可用的剑类型使其熟练度达到最高,且该熟练度高于其对所有其他可用剑类型的熟练度,那么该选手将随机选择其中一种表现最好的剑。注意,Charles 和 Delila 有可能选择同一种剑,这是允许的——每种类型的剑都有多个副本可供使用。

如果 Charles 选择的剑的熟练度与 Delila 选择的剑的熟练度之间的绝对差值不超过 $K$,则这场比赛是公平的。为了保持比赛的精彩程度,你想知道有多少种不同的对 $(L, R)$ 可以使比赛公平。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例的第一行包含两个整数 $N$ 和 $K$。接下来的两行描述熟练度:第一行包含 $N$ 个整数 $C_i$,表示 Charles 对每种剑的熟练度;第二行包含 $N$ 个整数 $D_i$,表示 Delila 对每种剑的熟练度。

输出格式

对于每个测试用例,输出一行 Case #x: y,其中 $x$ 是测试用例编号(从 $1$ 开始),$y$ 是能使比赛公平的选择方案数。

数据范围

$1 \le T \le 100$。 $0 \le K \le 10^5$。 $0 \le C_i \le 10^5$,对于所有 $i$。 $0 \le D_i \le 10^5$,对于所有 $i$。

子任务

测试集 1(可见): $1 \le N \le 100$。

测试集 2(隐藏): $N = 10^5$,共 8 个测试用例。 $1 \le N \le 1000$,其余所有测试用例。

样例

样例输入 1

6
4 0
1 1 1 8
8 8 8 8
3 0
0 1 1
1 1 0
1 0
3
3
5 0
0 8 0 8 0
4 0 4 0 4
3 0
1 0 0
0 1 2
5 2
1 2 3 4 5
5 5 5 5 10

样例输出 1

Case #1: 4
Case #2: 4
Case #3: 1
Case #4: 0
Case #5: 1
Case #6: 7

说明

在样例 1 中,当且仅当 Charles 可以使用最后一种剑时,比赛才是公平的,因此答案为 4。

在样例 2 中,有 4 场公平的比赛:$(1, 2), (1, 3), (2, 2)$ 和 $(2, 3)$。注意,对于像 $(1, 3)$ 这样的对,Charles 和 Delila 都有多种他们最擅长的剑可以选择;然而,每一对 $(L, R)$ 只计作一场公平的比赛。

在样例 3 中,有 1 场公平的比赛:$(1, 1)$。

在样例 4 中,没有公平的比赛,因此答案为 0。

在样例 5 中,请记住决斗者并不是为了让比赛公平而战;他们会选择自己最擅长的剑。例如,$(1, 3)$ 不是一场公平的比赛,因为 Charles 会选择第一种剑,而 Delila 会选择第三种剑。Delila 不会通过选择较弱的剑来放水!

在样例 6 中,有 7 场公平的比赛:$(1, 3), (1, 4), (2, 3), (2, 4), (3, 3), (3, 4)$ 和 $(4, 4)$。

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.