Increasing

Increasing

 

You are given an array aa of nn positive integers. Determine if, by rearranging the elements, you can make the array strictly increasing. In other words, determine if it is possible to rearrange the elements such that a_1 < a_2 < \dots < a_na1​<a2​<⋯<an​ holds.

Input

The first line contains a single integer tt (1 \leq t \leq 1001≤t≤100) — the number of test cases.

The first line of each test case contains a single integer nn (1 \leq n \leq 1001≤n≤100) — the length of the array.

The second line of each test case contains nn integers a_iai​ (1 \leq a_i \leq 10^91≤ai​≤109) — the elements of the array.

Output

For each test case, output "YES" (without quotes) if the array satisfies the condition, and "NO" (without quotes) otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

Sample 1

InputcopyOutputcopy
3
4
1 1 1 1
5
8 7 1 3 4
1
5
NO
YES
YES

Note

In the first test case any rearrangement will keep the array [1,1,1,1][1,1,1,1], which is not strictly increasing.

In the second test case, you can make the array [1,3,4,7,8][1,3,4,7,8].

——判断有没有相等元素即可,不能开数组存,耗时耗空间

#include <iostream>
#include <cstring>
#include <set>
using namespace std;

int main()
{
	int t;
	cin >> t;
	set<long long> s;
	for(int i=1;i<=t;i++)
	{
		s.clear();
		long long n, x, f = 0;
		cin >> n;
	for(int j=1;j<=n;j++)
		{
			int ls = s.size();

			cin >> x;
			s.insert(x);
//注意,尽管已经判断无法获得绝对增加数组,
//也要让他继续跑,因为还有元素未输入
			if (ls == s.size()&&f==0)

			{
				f = 1;
				cout << "NO" << endl;
			
			}
		}
		if (f == 0)
		{
			cout << "YES" << endl;
		}
		//cout << "&" << endl;
		/*for (set<long long>::iterator it = s.begin(); it != s.end(); it++)
		{
			cout << *it << " ";
		}
		cout << endl;*/
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

linalw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值