Language: C++

#include <bits/stdc++.h>
#ifdef _DEBUG
#include "_DEBUG.hpp"
#endif
#define int long long
using namespace std;
using P = pair<int, int>;
const int inf = 2e18;
const int mod = 1e9 + 7;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

template <class T>
vector<T> make_vec(size_t a) {
  return vector<T>(a);
}

template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template <class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
  t = v;
}

template <class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
  for (auto &e : t) fill(e, v);
}

template <class T>
struct SegmentTree{
  using F = function<T(T, T)>;
  F f;
  T inf;
  int n;
  vector<T> node;

  SegmentTree(){}
  SegmentTree(vector<T> v, T inf, F f) : inf(inf), f(f){
    n = 1; while(n < v.size()) n *= 2;
    node.resize(2*n-1, inf);
    for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
    for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1], node[2*i+2]);
  }

  void update(int k, T val){
    k += n-1;
    node[k] = val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1], node[2*k+2]);
    }
  }

  void add(int k, T val){
    k += n-1;
    node[k] += val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1], node[2*k+2]);
    }
  }

  //区間[a, b)の値を返す
  T operator[](int x){ return getval(x, x + 1); }
  T getval(int a, int b){ return getval(a, b, 0, 0, n); }
  T getval(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return node[k];
    T vl = getval(a, b, 2*k+1, l, (l+r)/2);
    T vr = getval(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }

  void print(int n){
    for(int i = 0; i < n; i++){
      cout << getval(i, i+1) << " ";
    }
    cout << endl;
  }
};

signed main() {
  
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  cin >> a;

  SegmentTree<int> seg(vector<int>(4e5 + 1, 0), -inf, [&](int x, int y){ return max(x, y); });
  for (int i = 0; i < n; i++) {
    int l = max(0ll, a[i] - k);
    int r = min(4e5, a[i] + k);
    seg.update(a[i], seg.getval(l, r + 1) + 1);
  }
  int ans = seg.getval(0, 4e5);
  cout << ans << endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:100:16: error: no matching function for call to 'min(double, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
  100 |     int r = min(4e5, a[i] + k);
      |             ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:100:16: note:   deduced conflicting types for parameter 'const _Tp' ('double' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  100 |     int r = min(4e5, a[i] + k);
      |             ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:100:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'double'
  100 |     int r = min(4e5, a[i] + k);
      |             ~~~^~~~~~~~~~~~~~~