QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓

#9889. 元素交换

Statistiques

DreamGrid 有一个整数序列 $a_1, a_2, \dots, a_n$,他非常喜欢这个序列。不幸的是,当 DreamGrid 不在家时,他淘气的室友 BaoBao 交换了序列中的两个元素 $a_i$ 和 $a_j$ ($1 \le i < j \le n$)。当 DreamGrid 回来时,他沮丧地发现他珍贵的序列变成了 $a_1, a_2, \dots, a_{i-1}, a_j, a_{i+1}, \dots, a_{j-1}, a_i, a_{j+1}, \dots, a_n$!

更糟糕的是,DreamGrid 记不清他原来的序列了。他只记得两个值: $$x = \sum_{k=1}^n k a_k \quad \text{和} \quad y = \sum_{k=1}^n k a_k^2$$

给定交换后的序列以及 DreamGrid 记得的两个值,请帮助 DreamGrid 计算 BaoBao 可能交换的元素对 $(a_i, a_j)$ 的数量。

注意,由于 DreamGrid 记性不好,$x$ 或 $y$ 的值可能与序列不匹配,在这种情况下可能找不到任何可能的元素对。

如果 $i \neq p$ 或 $j \neq q$,则两个元素对 $(a_i, a_j)$ ($1 \le i < j \le n$) 和 $(a_p, a_q)$ ($1 \le p < q \le n$) 被视为不同。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$,表示测试数据的组数。对于每组测试数据:

第一行包含三个整数 $n, x$ 和 $y$ ($2 \le n \le 10^5, 1 \le x, y \le 10^{18}$),表示序列的长度以及 DreamGrid 记得的两个值。

第二行包含 $n$ 个整数 $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^5$),表示交换后的序列。

保证 $\sum_{k=1}^n k b_k \le 10^{18}$ 且 $\sum_{k=1}^n k b_k^2 \le 10^{18}$。

保证所有测试数据的 $n$ 之和不超过 $2 \times 10^6$。

输出格式

对于每组测试数据,输出一行,包含一个整数,表示 BaoBao 可能交换的元素对的数量。

样例

样例输入 1

2
6 61 237
1 1 4 5 1 4
3 20190429 92409102
1 2 3

样例输出 1

2
0

说明

对于第一个样例测试数据,BaoBao 可能交换了第 2 个和第 3 个元素,或者第 5 个和第 6 个元素。

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.