Language: C++

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}

struct data{
    public:
    int pos;
    int range;

    data(int x, int y){pos=x; range=y;}
};
// 比較演算子の定義
bool operator<(const data &x, const data &y)
{
    return x.pos - x.range  < y.pos - y.range;
}


void execute()
{
    int N, K;
    cin >> N >> K;
    std::multiset<data> sA;
    std::multiset<data> sB;

    for(int i = 0; i < N; i++){
        int v;
        cin >> v;
        sA.insert(data(i, v));
    }

    auto &read = sA;
    auto &write = sB;

    for(int i = 0; i < K; i++){
        multiset<int> st;
        auto itrR = read.begin();

        for(int j = 0; j < N; j++){
            // 新規要素の追加
            do{
                if(itrR->pos - itrR->range <= j){
                    st.insert(itrR->pos + itrR->range);
                }else{
                    break;
                }
            }while(++itrR != read.end());

            // 要らないものの消去
            for(auto itr = st.begin(); itr != st.end();) {
                if(j <= *itr){
                    break;
                }
                itr = st.erase(itr);
            }

            write.insert(data(j, st.size()));
            if(i == K-1){
                cout <<  st.size() << " ";
            }
        }

        auto & t = read;
        read = write;
        write = t;
    }

    cout << endl;
}


Compiler output:
a.cc:29:22: error: reference to 'data' is ambiguous
   29 | bool operator<(const data &x, const data &y)
      |                      ^~~~
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:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:21:8: note:                 'struct data'
   21 | struct data{
      |        ^~~~
a.cc:29:37: error: reference to 'data' is ambiguous
   29 | bool operator<(const data &x, const data &y)
      |                                     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:21:8: note:                 'struct data'
   21 | struct data{
      |        ^~~~
a.cc:29:6: error: 'bool operator<(const int&, const int&)' must have an argument of class or enumerated type
   29 | bool operator<(const data &x, const data &y)
      |      ^~~~~~~~
a.cc: In function 'void execute()':
a.cc:39:23: error: template argument 1 is invalid
   39 |     std::multiset<data> sA;
      |                       ^
a.cc:39:23: error: template argument 2 is invalid
a.cc:39:23: error: template argument 3 is invalid
a.cc:40:23: error: template argument 1 is invalid
   40 |     std::multiset<data> sB;
      |                       ^
a.cc:40:23: error: template argument 2 is invalid
a.cc:40:23: error: template argument 3 is invalid
a.cc:45:12: error: request for member 'insert' in 'sA', which is of non-class type 'int'
   45 |         sA.insert(data(i, v));
      |            ^~~~~~
a.cc:45:19: error: reference to 'data' is ambiguous
   45 |         sA.insert(data(i, v));
      |                   ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:21:8: note:                 'struct data'
   21 | struct data{
      |        ^~~~
a.cc:53:26: error: request for member 'begin' in 'read', which is of non-class type 'int'
   53 |         auto itrR = read.begin();
      |                          ^~~~~
a.cc:63:35: error: request for member 'end' in 'read', which is of non-class type 'int'
   63 |             }while(++itrR != read.end());
      |                                   ^~~
a.cc:73:19: error: request for member 'insert' in 'write', which is of non-class type 'int'
   73 |             write.insert(data(j, st.size()));
      |                   ^~~~~~
a.cc:73:26: error: reference to 'data' is ambiguous
   73 |             write.insert(data(j, st.size()));
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:21:8: note:                 'struct data'
   21 | struct data{
      |        ^~~~