CF1463D.Pairs

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have 2n2n integers 1,2,…,2n1, 2, \dots, 2n. You have to redistribute these 2n2n elements into nn pairs. After that, you choose xx pairs and take minimum elements from them, and from the other n−xn - x pairs, you take maximum elements.

Your goal is to obtain the set of numbers b1,b2,…,bn{b_1, b_2, \dots, b_n} as the result of taking elements from the pairs.

What is the number of different xx-s (0≤x≤n0 \le x \le n) such that it's possible to obtain the set bb if for each xx you can choose how to distribute numbers into pairs and from which xx pairs choose minimum elements?

你有 2n2n 个整数 1,2,…,2n1, 2, \dots, 2n。你需要将这 2n2n 个元素重新分配为 nn 个数对。之后,你从中选择 xx 个数对,并从这 xx 个数对中各取最小值;而从其余 n−xn - x 个数对中,则各取最大值。

你的目标是:通过上述操作,恰好得到集合 {b1,b2,…,bn}\{b_1, b_2, \dots, b_n\}(即所取的 nn 个数构成该集合)。

问:满足条件的不同的 xx 的个数是多少(其中 0≤x≤n0 \le x \le n)?这里,“满足条件”指:对于该 xx,存在一种将 2n2n 个数划分为 nn 个数对的方式,以及一种从中选出 xx 个数对以取其最小值(其余取最大值)的方式,使得最终取出的 nn 个数的集合恰好为 bb。

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases.

The first line of each test case contains the integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5).

The second line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (1≤b1<b2<⋯<bn≤2n1 \le b_1 \lt b_2 \lt \dots \lt b_n \le 2n) — the set you'd like to get.

It's guaranteed that the sum of nn over test cases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 测试用例的数量。

每个测试用例的第一行包含整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)。

每个测试用例的第二行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(1≤b1<b2<⋯<bn≤2n1 \le b_1 \lt b_2 \lt \dots \lt b_n \le 2n)—— 你希望得到的集合。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print one number — the number of different xx-s such that it's possible to obtain the set bb.

对于每个测试用例,输出一个数字——即能够得到集合 bb 的不同 xx 的个数。

输入输出样例

  • 输入#1

    3
    1
    1
    5
    1 4 5 9 10
    2
    3 4

    输出#1

    1
    3
    1

说明/提示

In the first test case, x=1x = 1 is the only option: you have one pair (1,2)(1, 2) and choose the minimum from this pair.

In the second test case, there are three possible xx-s. If x=1x = 1, then you can form the following pairs: (1,6)(1, 6), (2,4)(2, 4), (3,5)(3, 5), (7,9)(7, 9), (8,10)(8, 10). You can take minimum from (1,6)(1, 6) (equal to 11) and the maximum elements from all other pairs to get set bb.

If x=2x = 2, you can form pairs (1,2)(1, 2), (3,4)(3, 4), (5,6)(5, 6), (7,9)(7, 9), (8,10)(8, 10) and take the minimum elements from (1,2)(1, 2), (5,6)(5, 6) and the maximum elements from the other pairs.

If x=3x = 3, you can form pairs (1,3)(1, 3), (4,6)(4, 6), (5,7)(5, 7), (2,9)(2, 9), (8,10)(8, 10) and take the minimum elements from (1,3)(1, 3), (4,6)(4, 6), (5,7)(5, 7).

In the third test case, x=0x = 0 is the only option: you can form pairs (1,3)(1, 3), (2,4)(2, 4) and take the maximum elements from both of them.

在第一个测试用例中,x=1x = 1 是唯一可行的选项:你只有一对 (1,2)(1, 2),并从中选取最小值。

在第二个测试用例中,存在三个可能的 xx 值。若 x=1x = 1,则可组成如下数对:(1,6)(1, 6)、(2,4)(2, 4)、(3,5)(3, 5)、(7,9)(7, 9)、(8,10)(8, 10)。你可以从 (1,6)(1, 6) 中取最小值(即 11),并从其余所有数对中取最大值,从而得到集合 bb。

若 x=2x = 2,则可组成数对 (1,2)(1, 2)、(3,4)(3, 4)、(5,6)(5, 6)、(7,9)(7, 9)、(8,10)(8, 10),并从 (1,2)(1, 2) 和 (5,6)(5, 6) 中取最小值,从其余数对中取最大值。

若 x=3x = 3,则可组成数对 (1,3)(1, 3)、(4,6)(4, 6)、(5,7)(5, 7)、(2,9)(2, 9)、(8,10)(8, 10),并从 (1,3)(1, 3)、(4,6)(4, 6)、(5,7)(5, 7) 中取最小值。

在第三个测试用例中,x=0x = 0 是唯一可行的选项:你可以组成数对 (1,3)(1, 3)、(2,4)(2, 4),并从这两对中均取最大值。

输入解题思路,AI测评打分。不知道怎么写?

首页