链接: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;elsecout<<"NO"<<endl;}}

C. Hilbert's Hotel相关推荐

  1. 【Codeforces 1344 A】Hilbert‘s Hotel,哈希表,set维护

    problem A. Hilbert's Hotel time limit per test1 second memory limit per test256 megabytes inputstand ...

  2. 2020双周训练训练日志

    第 3 次双周训练 VP A - 6789 签到题,按照题意模拟就行了,由于 lincong 将题目中的"中心对称"看成了"轴对称",导致 WA 了三发还不知道 ...

  3. codeforces 有意思的思维题 1 ~ 15

    codeforces 思维题 1.给定数组,求满足i < j and ai * aj = i + j的数对数量 2.第 i 步向前跳 i 步或后退 1 步 3.给两个点,求正方形的另两个点 4. ...

  4. python cv2 轮廓的包络 面积_Python 基于FIR实现Hilbert滤波器求信号包络详解

    在通信领域,可以通过希尔伯特变换求解解析信号,进而求解窄带信号的包络. 实现希尔伯特变换有两种方法,一种是对信号做FFT,单后只保留单边频谱,在做IFFT,我们称之为频域方法:另一种是基于FIR根据传 ...

  5. POJ 3667 Hotel(线段树)

    POJ 3667 Hotel 题目链接 题意:有n个房间,如今有两个操作 1.找到连续长度a的空房间.入住,要尽量靠左边,假设有输出最左边的房间标号,假设没有输出0 2.清空[a, a + b - 1 ...

  6. Hotel California

    On a dark desert highway 行驶在昏黑的荒漠公路上 cool wind in my hair 凉风吹过我的头发 warm smell of colutas 温馨的大麻香 risi ...

  7. 【 FPGA 】FIR滤波器之 Hilbert 变换的实现

    上篇博文:半带 FIR 滤波器(Half-band FIR Filter) 希尔伯特变换在数字通信系统中有很多种使用方式.理想的希尔伯特变换为正频率提供90度的相移,为负频率提供-90度的相移. 希尔 ...

  8. Analysis of the Clustering Properties of the Hilbert Space-Filling Curve 论文笔记

    摘要 已经针对各种应用提出了用于多维空间的线性映射的若干方案,诸如用于时空数据库的访问方法和图像压缩.在这些应用中,来自这种线性映射的最期望的属性之一是聚类,这意味着多维空间中的对象之间的局部性被保留 ...

  9. P2894 [USACO08FEB]酒店Hotel

    题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a ...

最新文章

  1. 在IIS7里配置 ISAPI,运行dll程序,总提示下载dll
  2. Delphi 的运算符重载(1)
  3. 关于ensp配置出现 Error: Please renew the default configurations.
  4. 好久没到这个地方来.
  5. 生成高斯热力图(craft中有使用)+2d heatmap+3d heatmap
  6. 微信小程序实现选项卡
  7. 截取字符串--sql和access的区别
  8. merge合并两个有序数组
  9. opencv 模板匹配,在图像中寻找物体
  10. 模糊测试--强制性安全漏洞发掘
  11. 关于shopex网店系统和网店助理的几点优化建议
  12. Fcitx 在 LumaQQ中的设置
  13. 三大框架搭建项目常见问题QA整理
  14. 每周写周报每天写总结
  15. 逻辑回归(logistics regression)
  16. arm-linux 看门狗,S3C6410看门狗源码实例
  17. 智能语音对话处理过程
  18. 【为您的 Android 应用添加图片】
  19. 大数据高级开发工程师——Spark学习笔记(4)
  20. 数据处理之标准化/归一化方法

热门文章

  1. Arduino设置esp8266实现局域网通信
  2. Android 禁止状态栏下拉
  3. tabindex的使用
  4. Python之print打印
  5. 电脑外设(I/O)简介:键盘鼠标
  6. 费马小定理 几道例题
  7. Eclipse安装与使用教程
  8. Cython入门:将python代码转为cython
  9. java 里面耦合和解耦
  10. PREEMPT-RT