Submission details
Task:Optimal sort
Sender:ind1f
Submission time:2025-10-27 16:26:41 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:45:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   45 |   sort(v.begin(), v.end());
      |   ^~~~
      |   short
input/code.cpp:46:11: error: 'unique' was not declared in this scope
   46 |   v.erase(unique(v.begin(), v.end()), v.end());
      |           ^~~~~~

Code

#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int N = 1e5 + 5;

struct fenwick_tree {
  int f[N];

  fenwick_tree() {
    memset(f, 0, sizeof(f));
  }

  void upd(int i, int x) {
    for (; i < N; i += i & -i) {
      f[i] = max(f[i], x);
    }
  }

  int get(int i) {
    int r = 0;
    for (; i > 0; i -= i & -i) {
      r = max(r, f[i]);
    }
    return r;
  }
};

int n;
int a[N];
fenwick_tree ft;
int f[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> v;
  copy(a + 1, a + n + 1, back_inserter(v));
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
    ft.upd(a[i], 1 + ft.get(a[i]));
  }
  cout << n - ft.get(N - 1) << '\n';
  return 0;
}