-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
127 lines (125 loc) · 2.52 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long ara[200005],b[200005];
int main()
{
fastio;
long long t,n,i,mex,gr,f,gs,s;
cin>>t;
while(t--)
{
cin>>n;
s=0;
map<long long,long long> mp;
for(i=0;i<n;i++)
{
cin>>ara[i];
b[i]=ara[i];
mp[ara[i]]++;
}
sort(b,b+n);
if(b[0]>0)
{
mex=0;
gr=n;
s=1;
}
else
{
for(i=1;i<n;i++)
{
if(b[i]>b[i-1]+1)
{
mex=b[i-1]+1;
gr=n-i+1;
s=1;
break;
}
}
}
if(s==0)
{
mex=b[n-1]+1;
gr=0;
}
if(n==1 && ara[0]==0)
{
cout<<"NO\n";
continue;
}
if(mp[mex+1]==1)
{
cout<<"YES\n";
continue;
}
if(mp[mex+1]==0)
{
if(b[n-1]>mex+1)
{
cout<<"YES\n";
continue;
}
s=0;
for(i=0;i<n;i++)
{
if(mp[b[i]]>1)
{
s=1;
break;
}
}
if(s==1)
{
cout<<"YES\n";
continue;
}
else
{
cout<<"NO\n";
continue;
}
}
gs=-1;
f=0;
for(i=0;i<n;i++)
{
if(ara[i]==mex+1)
{
if(gs==-1)
{
gs=0;
}
mp[mex+1]--;
if(mp[mex+1]==0)
break;
}
else if(ara[i]>mex+1)
{
continue;
}
else
{
if(gs==0)
{
if(mp[mex+1]>0)
{
if(mp[ara[i]]>1)
mp[ara[i]]--;
else
{
f=1;
break;
}
}
}
}
}
if(f==1)
cout<<"NO\n";
else
cout<<"YES\n";
}
return 0;
}