CF1781B.Going to the Cinema

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

A company of nn people is planning a visit to the cinema. Every person can either go to the cinema or not. That depends on how many other people will go. Specifically, every person ii said: "I want to go to the cinema if and only if at least aia_i other people will go, not counting myself". That means that person ii will become sad if:

  • they go to the cinema, and strictly less than aia_i other people go; or
  • they don't go to the cinema, and at least aia_i other people go.

In how many ways can a set of people going to the cinema be chosen so that nobody becomes sad?

一家有 nn 人的公司正计划集体去电影院。每个人可以选择去或不去电影院,该决定取决于最终实际去电影院的其他人人数。具体而言,每个人 ii 声称:“我愿意去电影院,当且仅当(即:恰好当)至少有 aia_i 个其他人去电影院(不包括我自己)。” 换句话说,若出现以下任一情况, person ii 将感到伤心:

  • 他/她去了电影院,但去的其他人人数严格少于 aia_i;或者
  • 他/她没去电影院,但去的其他人人数不少于 aia_i。

问:有多少种选择去电影院的人集合的方式,使得没有人感到伤心?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

Each test case consists of two lines. The first line contains a single integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the number of people in the company.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤n−10 \le a_i \le n - 1) — integers from peoples' claims.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例由两行组成。第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)—— 公司中的人数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤n−10 \le a_i \le n - 1)—— 各人所声称的数值。

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

输出格式

For each test case, print a single integer — the number of different ways to choose a set of people going to the cinema so that nobody becomes sad.

对于每个测试用例,输出一个整数——即选择一组去电影院的人的方式数目,使得没有人感到伤心。

输入输出样例

  • 输入#1

    4
    2
    1 1
    7
    0 1 2 3 4 5 6
    8
    6 0 3 3 6 7 2 7
    5
    3 0 0 3 3

    输出#1

    2
    1
    3
    2

说明/提示

In the first test case, both people want to go to the cinema if and only if the other person goes. There are two valid options: either both people go, or neither of them goes. However, if just one of them goes, both will be sad.

In the second test case, everyone has to go to the cinema. In any other case, someone will be sad.

In the third test case, there are three valid options: person number 22 goes to the cinema; or persons with indices 2,3,4,72, 3, 4, 7 go; or all eight people go.

在第一个测试用例中,两个人都希望去电影院当且仅当另一个人也去。存在两种合法方案:要么两人都去,要么两人都不去。然而,若仅有其中一人去,则两人都会感到难过。

在第二个测试用例中,所有人都必须去电影院。在任何其他情况下,都会有人感到难过。

在第三个测试用例中,存在三种合法方案:编号为 22 的人去电影院;或编号为 2,3,4,72, 3, 4, 7 的人去;或全部八个人都去。

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

首页