-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.cpp
63 lines (63 loc) · 1.11 KB
/
A.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
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int par[maxn];
int sub[maxn];
int p[maxn];
int vis[maxn];
int root(int x) {
if(x == par[x]) return par[x];
return par[x] = root(par[x]);
}
void join(int p, int q) {
p = root(p);
q = root(q);
if(p != q) {
par[p] = q;
sub[q] += sub[p];
}
}
void solve() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
p[x] = i;
}
for(int i = 1; i <= n + 1; i++) {
par[i] = i;
sub[i] = 1;
}
sub[n + 1] = -n - 1;
bool bad = false;
auto count = [&] (int x) {
return sub[root(x)];
};
multiset <int> s;
for(int i = 1; i <= n + 1; i++) {
s.insert(count(i));
}
for(int i = 1; i <= n; i++) {
int x = p[i];
// cout << x << ' ' << opt << ' ' << count(x) << endl;
if(count(x) != *s.rbegin()) {
bad = true;
break;
}
s.erase(s.find(count(x + 1)));
s.erase(s.find(count(x)));
join(x, x + 1);
s.insert(count(x));
}
if(bad) puts("No");
else puts("Yes");
}
int main() {
int t;
scanf("%d", &t);
while(t--) {
solve();
}
return 0;
}