CF1344A.Hilbert's Hotel
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer k and positive integer n, let kmodn denote the remainder when k is divided by n. More formally, r=kmodn is the smallest non-negative integer such that k−r is divisible by n. It always holds that 0≤kmodn≤n−1. For example, 100mod12=4 and (−1337)mod3=1.
Then the shuffling works as follows. There is an array of n integers a0,a1,…,an−1. Then for each integer k, the guest in room k is moved to room number k+akmodn.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
希尔伯特旅馆是一家非常特殊的旅馆,因为它的房间数量是无限的!事实上,每一个整数(包括零和负整数)都恰好对应一个房间。更奇特的是,该旅馆当前已客满,即每个房间中恰好住着一位客人。旅馆经理——大卫·希尔伯特本人——决定重新安排客人,因为他认为这样可以腾出一个空房间(即某个房间中没有客人)。
对于任意整数 k 和正整数 n,记 kmodn 为 k 除以 n 所得的余数。更严格地定义:r=kmodn 是满足 k−r 被 n 整除的最小非负整数。该定义恒保证 0≤kmodn≤n−1。例如,100mod12=4,而 (−1337)mod3=1。
重排规则如下:给定一个长度为 n 的整数数组 a0,a1,…,an−1。对每个整数 k,原住在房间 k 的客人将被移至房间 k+akmodn。
在完成此次重排后,请判断是否仍然每个房间恰好分配了一位客人(即既无空房间,也无多个客人同住一房)。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. Next 2t lines contain descriptions of test cases.
The first line of each test case contains a single integer n (1≤n≤2⋅105) — the length of the array.
The second line of each test case contains n integers a0,a1,…,an−1 (−109≤ai≤109).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。接下来的 2t 行包含各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105),表示数组的长度。
每个测试用例的第二行包含 n 个整数 a0,a1,…,an−1(−109≤ai≤109)。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
对于每个测试用例,如果洗牌过程结束后每个房间恰好分配到一名客人,则输出一行“YES”;否则输出“NO”。每个字母可使用大写或小写形式。
输入输出样例
输入#1
6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11
输出#1
YES YES YES NO NO YES
说明/提示
In the first test case, every guest is shifted by 14 rooms, so the assignment is still unique.
In the second test case, even guests move to the right by 1 room, and odd guests move to the left by 1 room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by 1 room, and the other guests move to the right by 5 rooms. We can show that the assignment is still unique.
In the fourth test case, guests 0 and 1 are both assigned to room 3.
In the fifth test case, guests 1 and 2 are both assigned to room 2.
在第一个测试用例中,每位客人均向右移动 14 个房间,因此分配方案仍然是唯一的。
在第二个测试用例中,偶数编号的客人向右移动 1 个房间,奇数编号的客人向左移动 1 个房间。可以证明该分配方案仍然是唯一的。
在第三个测试用例中,每第四个客人(即编号为 0,4,8,… 的客人)向右移动 1 个房间,其余客人向右移动 5 个房间。可以证明该分配方案仍然是唯一的。
在第四个测试用例中,客人 0 和 1 均被分配至房间 3。
在第五个测试用例中,客人 1 和 2 均被分配至房间 2。
输入解题思路,AI测评打分。不知道怎么写?