-
Notifications
You must be signed in to change notification settings - Fork 10
/
1401.cpp
99 lines (87 loc) · 1.45 KB
/
1401.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
/*
* Author : Akansha
* 4/10/20
*
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007
void inp()
{
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
}
ll min(ll a,ll b)
{
if(a<b)
return a;
else
return b;
}
ll max(ll a,ll b)
{
if(a>b)
return a;
else
return b;
}
int main() {
inp();
fio;
ll t;
cin >> t;
while (t--) {
ll n;
cin>>n;
vector<int> v(n),a(n);
ll min_ele=INT_MAX;
for(int i=0;i<n;i++)
{
cin>>v[i];
a[i]=v[i];
min_ele=min(min_ele,v[i]);
}
sort(v.begin(),v.end());
unordered_map<int,int> mp1;
unordered_map<int,int> mp2;
for(int i=0;i<n;i++)
{
mp1[v[i]]=i;
if(mp2.find(v[i])==mp2.end())
{
mp2[v[i]]=i;
}
}
int flag=0;
for(int i=0;i<n;i++)
{
//cout<<mp[a[i]]<<" "<<a[i]<<endl;
if(mp2[a[i]]>i && a[i]%min_ele!=0)
{
flag=1;
break;
}
if(mp1[a[i]]<i && a[i]%min_ele!=0)
{
flag=1;
break;
}
}
if(flag)
{
cout<<"NO\n";
}
else
{
cout<<"YES\n";
}
}
return 0;
}