Language: C++

#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;
const int INF=1e9;

template<typename T> class LazySegmentTree
{
 private:
    int n;
    vector<T> node,lazy;
 public:
    LazySegmentTree(int sz,T init){
        n=1;
        while(n<sz) n*=2;
        node.assign(2*n-1,init);
        lazy.assign(2*n-1,-1);
    }
    void update(int a,int b,int x,int k,int l,int r){
        if(a<=l and r<=b) node[k]=lazy[k]=x;
        else{
            if(lazy[k]!=-1) push(k),lazy[k]=-1;
            if(check(a,b,l,(l+r)/2)) update(a,b,x,2*k+1,l,(l+r)/2);
            if(check(a,b,(l+r)/2,r)) update(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=min(node[2*k+1],node[2*k+2]);
        }
    }
    T get(int a,int b,int k,int l,int r){
        if(a<=l and r<=b) return node[k];
        else{
            if(lazy[k]!=-1) push(k),lazy[k]=-1;
            T res=INT_MAX;
            if(check(a,b,l,(l+r)/2)) res=min(res,get(a,b,2*k+1,l,(l+r)/2));
            if(check(a,b,(l+r)/2,r)) res=min(res,get(a,b,2*k+2,(l+r)/2,r));
            return res;
        }
    }
    void push(int k){
        node[2*k+1]=node[2*k+2]=lazy[k];
        lazy[2*k+1]=lazy[2*k+2]=lazy[k];
    }
    bool check(int a,int b,int l,int r){
        return max(a,l)<min(b,r);
    }
    void update(int a,int b,int x){ update(a,b,x,0,0,n); }
    T get(int a,int b){ return get(a,b,0,0,n); }
};

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N,M; cin>>N>>M;
    string s; cin>>s;

    LazySegmentTree<int> seg(N+1,INF);
    seg.update(N,N+1,0);
    int R=N;
    for(int i=N;i>=1;i--) if(s[i]=='0'){
        if(seg.get(i,i+1)>=INF) continue;
        int L=max(0,i-M);
        // cout<<L<<' '<<R<<' '<<seg.get(i,i+1)<<endl;
        if(L<=R) seg.update(L,R,seg.get(i,i+1)+1);
        chmin(R,L);
        // for(int i=0;i<=N;i++) cout<<seg.get(i,i+1)<<' '; cout<<endl;
    }

    int mn=seg.get(0,1);
    if(mn>=INF){
        cout<<-1<<endl;
        return 0;
    }
    vector<int> ans(mn,-1);
    for(int i=0;i<=N;i++) if(s[i]!='1'){
        int x=seg.get(i,i+1);
        if(ans[x]==-1) ans[x]=i;
    }

    for(int i=mn;i>=1;i--){
        cout<<ans[i-1]-ans[i]<<' ';
    }
    cout<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:65:18: error: no matching function for call to 'max(int, long long int)'
   65 |         int L=max(0,i-M);
      |               ~~~^~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:65:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   65 |         int L=max(0,i-M);
      |               ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:65:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   65 |         int L=max(0,i-M);
      |               ~~~^~~~~~~