Language: C++

#include<bits/stdc++.h>
using namespace std;

const long long INF=0;
long long size,node[100000000];
void init(long long N_){
    size=1;
    while(size<N_)size*=2;
    for(long long i=0;i<2*size-1;i++)node[i]=INF;
}
void update(long long a,long long x){
    a+=size-1;
    node[a]=x;
    while(a>0){
        a=(a-1)/2;
        node[a]=max(node[2*a+1],node[2*a+2]);
    }
}
long long query(long long a,long long b,long long k,long long l,long long r){
    if(b<=l||r<=a)return INF;
    if(a<=l&&r<=b)return node[k];
    long long vl=query(a,b,2*k+1,l,(l+r)/2);
    long long vr=query(a,b,2*k+2,(l+r)/2,r);
    return max(vl,vr);
}

int main(void)
{
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N);
    for (long long i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    init(300001);
    for (long long i = 0; i < N; i++)
    {
        long long premin = max((long long)1, A[i]-K);
        long long premax = min((long long)300000, A[i]+K);
        long long num = query(premin-1, premax, 0, 0, size);
        update(A[i], num+1);
    }
    long long ans = query(1, size-1, 0, 0, size);
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'void init(long long int)':
a.cc:7:5: error: reference to 'size' is ambiguous
    7 |     size=1;
      |     ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:11: note:                 'long long int size'
    5 | long long size,node[100000000];
      |           ^~~~
a.cc:8:11: error: reference to 'size' is ambiguous
    8 |     while(size<N_)size*=2;
      |           ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:11: note:                 'long long int size'
    5 | long long size,node[100000000];
      |           ^~~~
a.cc:8:19: error: reference to 'size' is ambiguous
    8 |     while(size<N_)size*=2;
      |                   ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:11: note:                 'long long int size'
    5 | long long size,node[100000000];
      |           ^~~~
a.cc:9:27: error: reference to 'size' is ambiguous
    9 |     for(long long i=0;i<2*size-1;i++)node[i]=INF;
      |                           ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:11: note:                 'long long int size'
    5 | long long size,node[100000000];
      |           ^~~~
a.cc: In function 'void update(long long int, long long int)':
a.cc:12:8: error: reference to 'size' is ambiguous
   12 |     a+=size-1;
      |        ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:11: note:                 'long long int size'
    5 | long long size,node[100000000];
      |           ^~~~
a.cc: In function 'int main()':
a.cc:41:55: error: reference to 'size' is ambiguous
   41 |         long long num = query(premin-1, premax, 0, 0, size);
      |                                                       ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:11: note:                 'long long int size'
    5 | long long size,node[100000000];
      |           ^~~~
a.cc:44:30: error: reference to 'size' is ambiguous
   44 |     long long ans = query(1, size-1, 0, 0, size);
      |                              ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:11: note:                 'long long int size'
    5 | long long size,node[100000000];
      |           ^~~~
a.cc:44:44: error: reference to 'size' is ambiguous
   44 |     long long ans = query(1, size-1, 0, 0, size);
      |                                            ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:11: note:                 'long long int size'
    5 | long long size,node[100000000];
      |           ^~~~