fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <algorithm>
  5. #include <set>
  6. using namespace std;
  7.  
  8. int main() {
  9. cin.tie(0)->sync_with_stdio(0);
  10. int t;
  11. cin >> t;
  12. while (t--) {
  13. int n, index = 0;
  14. cin >> n;
  15. vector <int> a(n);
  16. vector <bool> e(n, false);
  17. set <int> s;
  18. for(int i = 0; i < n; i++){
  19. s.insert(i+1);
  20. }
  21. for(int i = 0; i < n; i++){
  22. cin >> a[i];
  23. if(s.count(a[i])) s.erase(a[i]);
  24. else e[i] = true;
  25. }
  26. auto temp = s.begin();
  27. for(int i = 0; i < n; i++){
  28. if(e[i]){
  29. a[i] = *temp;
  30. temp++;
  31. }
  32. cout << a[i] << " ";
  33. }
  34. cout << endl;
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5288KB
stdin
4
2
1 2
4
1 1 1 2
8
4 5 5 5 1 1 2 1
10
1 1 2 2 1 1 3 3 1 1
stdout
1 2 
1 3 4 2 
4 5 3 6 1 7 2 8 
1 4 2 5 6 7 3 8 9 10