Language: C++

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int par[200005];
int s[200005];
int rank[200005];
set<int>ss;
void init(int n) {
  for(int i = 0; i <= n; i++) {
    par[i] = i;
    s[i] = 0;
    rank[i] = 0;
  }
  return;
}

int f(int x) {
  return (x == par[x]) ? x : (par[x] = f(par[x]));
}
void u(int x, int y) {
  int a = f(x);
  int b = f(y);
  if(a == b) return;
  s[a] += s[b];
  s[b] = s[a];
  if(rank[a] > rank[b]) {
    par[b] = a;
  }
  else {
    par[a] = b;
    if(rank[a] == rank[b]) rank[a]++;
  }
}
    
  
int main() {
  int n;
  cin >> n;
  init(n);
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if(ss.find(a) == ss.end()) {
      s[a]++;
      ss.insert(a);
    }
    if(s[a-1] > 0) {
      u(a,a-1);
    }
  }
      

  int ans = 0;
  for(int i = 0; i <= n; i++) {
    ans = max(ans,s[i]);
   // cout <<i<<"   "<<s[i] << endl;
    }

  cout << n - ans << endl;
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:13:5: error: reference to 'rank' is ambiguous
   13 |     rank[i] = 0;
      |     ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [200005]'
    7 | int rank[200005];
      |     ^~~~
a.cc: In function 'void u(int, int)':
a.cc:27:6: error: reference to 'rank' is ambiguous
   27 |   if(rank[a] > rank[b]) {
      |      ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [200005]'
    7 | int rank[200005];
      |     ^~~~
a.cc:27:16: error: reference to 'rank' is ambiguous
   27 |   if(rank[a] > rank[b]) {
      |                ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [200005]'
    7 | int rank[200005];
      |     ^~~~
a.cc:32:8: error: reference to 'rank' is ambiguous
   32 |     if(rank[a] == rank[b]) rank[a]++;
      |        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [200005]'
    7 | int rank[200005];
      |     ^~~~
a.cc:32:19: error: reference to 'rank' is ambiguous
   32 |     if(rank[a] == rank[b]) rank[a]++;
      |                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [200005]'
    7 | int rank[200005];
      |     ^~~~
a.cc:32:28: error: reference to 'rank' is ambiguous
   32 |     if(rank[a] == rank[b]) rank[a]++;
      |                            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [200005]'
    7 | int rank[200005];
      |     ^~~~