Given is a sequence of integers A1,A2,…,AN. If its elements are pairwise distinct, print YES; otherwise, print NO.
Constraints
·2≤N≤200000
·1≤Ai≤109
·All values in input are integers.
Input is given from Standard Input in the following format:
N
A1 … AN
输出
If the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.
样例输入 Copy
【样例1】
5
2 6 1 4 5
【样例2】
6
4 1 3 1 6 2
【样例3】
2
10000000 10000000
样例输出 Copy
【样例1】
YES
【样例2】
NO
【样例3】
NO
提示
样例1解释
The elements are pairwise distinct.
样例2解释
The second and fourth elements are identical.
这个题如果一个一个遍历估计会超时,正好用上刚学的set,自动存储时去重,最后只需要比较个数就好,不多说,贴码
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
set <int> s;
int a[200020];
int i,n;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
s.insert(a[i]);
}
int cnt=0;
set<int>::iterator it;
for(it=s.begin();it!=s.end();it++)
{
cnt++;
}
if(cnt==n)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}