fork download
  1. #include <bits/stdc++.h>
  2. #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  3. # define ll long long int
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. ll t;
  11. cin>>t;
  12. while(t--)
  13. {
  14. ll n;
  15. cin>>n;
  16. set<int>s;
  17. int a[n];
  18. for(int i=0;i<n;i++)
  19. cin>>a[i];
  20. int mx=0;
  21. for(int i=0;i<n;i++)
  22. mx=max(mx,a[i]);
  23. mx++;
  24. unordered_map<int,int>mp;
  25. for(int i=0;i<n;i++)
  26. mp[a[i]]++;
  27. vector<int>ans;
  28. for(int i=0;i<n;i++)
  29. {
  30. mp[a[i]]--;
  31. s.insert(a[i]);
  32. ll x=0;
  33. for(auto &z:s)
  34. {
  35. if(z!=x)
  36. break;
  37. x++;
  38. }
  39. if(mp[x]==0)
  40. {
  41. ans.push_back(x);
  42. s.clear();
  43. }
  44. }
  45. cout<<ans.size()<<endl;
  46. for(int i=0;i<ans.size();i++)
  47. cout<<ans[i]<<endl;
  48.  
  49.  
  50. }
  51. return 0;
  52. }
Success #stdin #stdout 0.01s 5480KB
stdin
6
5
1 0 2 0 3
8
2 2 3 4 0 1 2 0
1
1
5
0 1 2 3 4
4
0 1 1 0
10
0 0 2 1 1 1 0 0 1 1
stdout
1
4
2
5
1
1
0
1
5
2
2
2
4
3
2
2
0