QOJ.ac

QOJ

Time Limit: 10.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#7001. 连续区间

Statistics

Lamis 是一个聪明的女孩。她对关于序列及其区间的题目很感兴趣。

她向你展示了一个长度为 $n$ 的正整数序列,记作 $a_1, a_2, a_3, \dots, a_n$。她对这些区间(即 $a_1, a_2, \dots, a_n$ 的连续子序列)中包含连续数字的区间感到惊叹,并将它们称为“连续区间”。

更准确地说,考虑一个区间 $a_l, a_{l+1}, \dots, a_{r-1}, a_r$,其中 $1 \le l \le r \le n$。如果将该区间排序后,任意两个相邻元素的差值小于或等于 $1$,则该区间被视为连续的。

作为她最好的朋友,你从四面八方赶来,跋涉千里来到宁夏,帮助她计算该序列中连续区间的数量。

输入格式

输入包含多个测试用例,第一行是一个正整数 $T$,表示测试用例的数量,最多为 $1000$。

对于每个测试用例,第一行包含一个整数 $n$ ($1 \le n \le 10^5$),表示给定序列的长度。第二行包含 $n$ 个整数,描述序列的所有项,其中第 $i$ 项记为 $a_i$ ($1 \le a_i \le 10^9$)。

保证所有测试用例中 $n$ 的总和不超过 $10^6$。

输出格式

对于每个测试用例,输出一行 Case #x: y,其中 $x$ 是从 $1$ 开始的测试用例编号,$y$ 是该测试用例中连续区间的数量。

样例

样例输入 1

2
4
1 2 1 2
4
1 3 2 4

样例输出 1

Case #1: 10
Case #2: 8

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.