C. Hilbert's Hotel

探讨希尔伯特无限酒店中客人重新分配的问题,通过数组操作模拟客人在房间间的移动,判断移动后每个房间是否仍恰好有一名客人。使用C++实现,通过取模运算和数组标记来检查是否有重复分配。

链接:https://codeforces.ml/contest/1345/problem/C

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 kk and positive integer nn, let kmodnkmodn denote the remainder when kk is divided by nn. More formally, r=kmodnr=kmodn is the smallest non-negative integer such that k−rk−r is divisible by nn. It always holds that 0≤kmodn≤n−10≤kmodn≤n−1. For example, 100mod12=4100mod12=4 and (−1337)mod3=1(−1337)mod3=1.

Then the shuffling works as follows. There is an array of nn integers a0,a1,…,an−1a0,a1,…,an−1. Then for each integer kk, the guest in room kk is moved to room number k+akmodnk+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.

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. Next 2t2t lines contain descriptions of test cases.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the length of the array.

The second line of each test case contains nn integers a0,a1,…,an−1a0,a1,…,an−1 (−109≤ai≤109−109≤ai≤109).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.

Output

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).

Example

input

Copy

6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11

output

Copy

YES
YES
YES
NO
NO
YES

Note

In the first test case, every guest is shifted by 1414 rooms, so the assignment is still unique.

In the second test case, even guests move to the right by 11 room, and odd guests move to the left by 11 room. We can show that the assignment is still unique.

In the third test case, every fourth guest moves to the right by 11 room, and the other guests move to the right by 55 rooms. We can show that the assignment is still unique.

In the fourth test case, guests 00 and 11 are both assigned to room 33.

In the fifth test case, guests 11 and 22 are both assigned to room 22.

代码:

#include <bits/stdc++.h>
using namespace std;
long long n,m,t,k,s,mod=1e9+7;
long long a[200001],b[200001];
int main() 
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		int flag=1;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			b[i]=0;
		}
		for(int i=0;i<n;i++)
		{
			k=i+(a[i]%n+n)%n;
			k%=n;
			//cout<<k<<" ";
			if(b[k]==0)
			{
				b[k]=1;
			}
			else
			{
				flag=0;
				break;
			}
		}
		if(flag==1)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	
}

 

### 代码功能 代码 `ufi[i,:] = fftpack.hilbert(uf[i,:])` 的主要功能是对数组 `uf` 的第 `i` 行应用希尔伯特变换,并将变换结果赋值给数组 `ufi` 的第 `i` 行。希尔伯特变换是一种信号处理技术,常用于将实值信号转换为解析信号。解析信号的虚部是实部(原始信号)的希尔伯特变换结果,通过希尔伯特变换可以方便地提取信号的幅度、相位和瞬时频率等信息。 ### 使用方法 以下是一个完整的示例代码,展示了如何使用 `fftpack.hilbert` 函数: ```python import numpy as np from scipy import fftpack # 生成一个示例数组 uf uf = np.random.rand(10, 100) # 10 行 100 列的随机数组 # 创建一个与 uf 相同形状的数组 ufi ufi = np.zeros_like(uf) # 选择第 i 行进行希尔伯特变换 i = 2 # 例如,选择第 2 行 # 应用希尔伯特变换 ufi[i, :] = fftpack.hilbert(uf[i, :]) print(ufi[i, :]) ``` 在这个示例中,首先导入了 `numpy` 和 `scipy.fftpack` 模块。然后生成了一个随机数组 `uf`,并创建了一个与 `uf` 相同形状的零数组 `ufi`。接着选择了第 `i` 行(这里 `i` 为 2),对该行应用希尔伯特变换,并将结果赋值给 `ufi` 的第 `i` 行。最后打印出变换后的结果。 ### 可能的报错处理 #### 1. `ImportError` 如果在导入 `fftpack.hilbert` 时出现 `ImportError`,这通常意味着 `scipy` 库没有正确安装。可以使用以下命令来安装 `scipy`: ```sh pip install scipy ``` #### 2. `IndexError` 如果出现 `IndexError`,这可能是因为指定的索引 `i` 超出了数组 `uf` 的有效范围。在使用索引之前,需要确保索引值在数组的有效范围内。可以添加以下检查代码: ```python if i < 0 or i >= uf.shape[0]: raise IndexError("Index i is out of bounds.") ``` #### 3. `TypeError` 如果输入的数组不是有效的 `numpy` 数组,可能会出现 `TypeError`。在使用 `fftpack.hilbert` 之前,需要确保输入的是 `numpy` 数组。可以使用 `np.asarray` 函数将输入转换为 `numpy` 数组: ```python uf_row = np.asarray(uf[i, :]) ufi[i, :] = fftpack.hilbert(uf_row) ```
评论 9
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值