QOJ.ac

QOJ

حد الوقت: 4.0 s حد الذاكرة: 512 MB مجموع النقاط: 100

#9324. 特征之和

الإحصائيات

给定一个包含 $n$ 个随机整数的数组 $a$,其中每个整数都在 $1$ 到 $n$ 之间。对于其子段 $[\ell, r]$,其特征值(characteristic)定义为:

$$C(\ell, r) = \min_{\ell \le i < j \le r} \max(a_i + j, a_j + i)$$

你的任务是计算:

$$\sum_{\ell=1}^{n} \sum_{r=\ell+1}^{n} C(\ell, r)$$

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 3 \cdot 10^5$),表示测试用例的数量。接下来是各测试用例。 每个测试用例的第一行包含一个整数 $n$,表示数组的大小 ($1 \le n \le 3 \cdot 10^5$)。下一行包含数组本身:$n$ 个 $1$ 到 $n$ 之间的整数,由伪随机数生成器均匀且独立地生成。 所有测试用例的 $n$ 之和不超过 $3 \cdot 10^5$。

输出格式

对于每个测试用例,输出一行,包含一个整数,表示所有子段特征值的总和。

样例

样例输入 1

3
2
2 1
5
3 5 4 1 4
6
1 4 6 1 6 3

样例输出 1

4
72
112

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.