fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  4. #define int long long
  5. #define rep(i,a,b) for(int i=a;i<b;++i)
  6.  
  7. int LIS_length(const vector<int>& a) {
  8. vector<int> d;
  9. for (int x : a) {
  10. auto it = lower_bound(d.begin(), d.end(), x);
  11. if (it == d.end()) d.push_back(x);
  12. else *it = x;
  13. }
  14. return (int)d.size();
  15. }
  16.  
  17. void solve() {
  18. int n;
  19. cin>>n;
  20. vector<int> a(n);
  21. rep(i,0,n) cin>>a[i];
  22. cout << n - LIS_length(a) << '\n';
  23. }
  24.  
  25. int32_t main() {
  26. fast_io;
  27. int t;
  28. cin >> t;
  29. while (t--) solve();
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0.01s 5284KB
stdin
5
3
3 2 1
3
1 2 3
3
3 3 3
5
3 1 4 5 2
1
1
stdout
2
0
2
2
0