Managing Difficulties

在Codehorses上,每天都有新的编程问题发布。Polycarp想要选择三天,使得中间一天的问题难度与第一天的难度之差等于最后一天与中间一天的难度之差。计算满足条件的组合数。输入包含测试用例,每个用例给出问题天数和各天的难度。输出每个测试用例的组合数。题目要求使用unordered_map优化算法。
摘要由CSDN通过智能技术生成

Managing Difficulties

Every day a new programming problem is published on Codehorses. Thus, n problems will be published in the following n days: the difficulty of the ii-th problem is ai.

Polycarp wants to choose exactly three days i, j and k (i<j<k) so that the difference of difficulties on the day j and the day i is equal to the difference of difficulties on the day k and day j. In other words, Polycarp wants equality aj−ai=ak−aj to be true.

Determine the number of possible ways for Polycarp to choose the three days in the desired way.

Input
The first line contains an integer t — the number of test cases in the input (1≤t≤10). Then t test case descriptions follow.

The first line of a test case contains an integer n — the number of the days (3≤n≤2000).

The second line of the test case contains n integers a1,a2,…,an, where ai is the difficulty of the problem on the i-th day (1≤ai≤10^9).

Output
Output t integers — the answers for each of the test cases in the input, in the order they are given. The answer to a test case is the number of triples of indices i, j, and k such that 1≤i<j<k≤n and ak−aj=aj−ai.

Example
input
4
5
1 2 1 2 1
3
30 20 10
5
1 2 2 3 4
9
3 1 4 1 5 9 2 6 5
output
1
1

GNU Make 是一个广泛使用的项目管理工具,它可以帮助我们自动化构建和管理项目。它的核心思想是基于规则来定义项目的构建过程。 首先,我们需要在项目的根目录中创建一个名为“Makefile”的文件,用于定义项目的规则和依赖关系。Makefile 是用来告诉 GNU Make 如何构建和更新项目的文件,它由一系列规则组成。 每个规则由一个目标(target)和相应的依赖列表组成。目标是指我们希望生成的文件或执行的操作,而依赖列表则表示生成目标所需要的文件或操作。当某个目标的依赖发生变化时,GNU Make 将会自动检测并更新相应的目标。 在 Makefile 中,我们可以使用一些预定义的变量来简化配置,如 CC 表示编译器,CFLAGS 表示编译选项等。我们还可以定义自己的变量,以便在规则中使用。 通过定义规则和依赖关系,我们可以利用 GNU Make 来自动构建项目。当我们运行 make 命令时,GNU Make 将会读取 Makefile,并根据规则和依赖关系来判断哪些目标需要重新构建,然后执行相应的命令。 GNU Make 还支持一些高级特性,如条件判断、循环、递归等,这使得我们可以根据不同的情况来定义不同的规则和行为。 总之,GNU Make 是一个强大而灵活的项目管理工具,它允许我们根据项目的需求来定义规则和依赖关系,并自动化构建过程,提高项目的开发效率和可维护性。无论是小型项目还是大型项目,GNU Make 都是一个极为有用的工具。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值