Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. // https://codeforces.com/contest/1223/problem/D
  2. #include<iostream>
  3. #include<vector>
  4. using namespace std;
  5.  
  6.  
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12.     ios_base::sync_with_stdio(false);
  13.     cin.tie(NULL);
  14.     int Q;
  15.     cin >> Q;
  16.     for(int q = 0; q < Q; ++q)
  17.     {
  18.         int n;
  19.         cin >> n;
  20.         vector<int> a(n), first(n, n), last(n, -1);
  21.         for(int i = 0; i < n; ++i)
  22.         {
  23.             cin >> a[i];
  24.             a[i]--;
  25.             first[a[i]] = min(first[a[i]], i);
  26.             last[a[i]] = max(last[a[i]], i);
  27.         }
  28.         vector<int> unique;
  29.         for(int i = 0; i < n; ++i)
  30.         {
  31.              if(last[i] != -1) unique.push_back(i);
  32.         }
  33.         int current = 1;
  34.         int ans = 1;
  35.         for(int i = 0; i < unique.size() - 1; ++i)
  36.         {
  37.             if(last[unique[i]] < first[unique[i + 1]])
  38.             {
  39.                 current++;
  40.                 ans = max(ans, current);
  41.             }
  42.             else current = 1;
  43.  
  44.         }
  45.         cout << unique.size() - ans << endl;
  46.  
  47.  
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement