from collections import Counter
def mex():
mex_val = 0
while (mex_val <= n):
if (mex_val not in s):
return mex_val
mex_val += 1
return mex_val
for _ in range(int(input())):
n = int(input())
arr = [int(item) for item in input().split()]
c = Counter(arr)
s = set(arr)
ans = []
i=0
while(i<n):
m = mex()
z = set()
while (i < n):
if (arr[i] < m):
z.add(arr[i])
c[arr[i]] -= 1
if (c[arr[i]] == 0):
s.remove(arr[i])
if (len(z) == m):
break
i += 1
ans.append(m)
i += 1
print(len(ans))
print(*ans)
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define pb push_back
int main()
{
int t;
cin>>t;
while (t--){
int n;
cin>>n;
vi a(n + 1);
vvi pos(n + 2);//if mex == n + 1 => pos[n + 1] is empty
for (int i = 1;i<=n;i++){
cin>>a[i];
pos[a[i]].pb(i);//add index i to the set of positions[a[i]]
}
int l = 1;
vi b;//final answer
while (l <= n){
int mex = 0;
int r = l;//[l, l]
for (;mex <= n + 1;mex++){
auto it = lower_bound(pos[mex].begin(),pos[mex].end(),l);
if (it == pos[mex].end())//no occurrence of mex in the range [i, n]
break;
r = max(r, *it);
}
b.pb(mex);
l = r + 1;
}
cout<<(int)b.size()<<endl;
for (auto it:b)cout<<it<<" ";
cout<<endl;
}
return 0;
}
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |
Back to School | I am Easy |
Teddy and Tweety | Partitioning binary strings |
Special sets | Smallest chosen word |
Going to office | Color the boxes |
Missing numbers | Maximum sum |
13 Reasons Why | Friend's Relationship |
Health of a person | Divisibility |
A. Movement | Numbers in a matrix |
Sequences | Split houses |
Divisible | Three primes |
Coprimes | Cost of balloons |
One String No Trouble | Help Jarvis! |