/*************************************************************************
    > File Name: E.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com
    > Created Time: 2019年04月17日 星期三 10时52分04秒
 ************************************************************************/

#include<bits/stdc++.h>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define P pair<int,int>
using namespace std;
const int N = 2E5+10;
int f[N],vc[N],a[N];
bool vis[N];
int getF(int v)
{
    if(f[v] == v) return v;
    return f[v] = getF(f[v]);
}

void mrge(int u,int v)
{
    int p = getF(u);
    int q = getF(v);
    if(p != q) f[p] = q;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
    ios::sync_with_stdio(false); cin.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        vc[a[i]] = i;
    }
    for(int i = 1; i <= n + 2; ++i) f[i] = i;
    int cur = 0;
    for(int i = n; i >= 1; --i) {
        if(vis[vc[i]] == 1) continue;
        vis[vc[i]] = 1;
        mrge(vc[i], n + 1 + cur);
        for(int l = 1, d = 1; d <= k && vc[i] + l <= n; ++l) {
            if(vis[vc[i] + l]) {
                l += 2 * k;
                continue;
            }
            ++d;
            vis[vc[i] + l] = 1;
            mrge(vc[i] + l, vc[i]);
        }
        for(int r = 1, d = 1; d <= k && vc[i] - r >= 1; ++r) {
            if(vis[vc[i] - r]) {
                r -= 2 * k;
                continue;
            }
            ++d;
            vis[vc[i] - r] = 1;
            mrge(vc[i] - r, vc[i]);
        }
        cur ^= 1;
    }
    for(int i = 1; i <= n; ++i) {
        cout << getF(i) - n << ' ';
    }
    return 0;
}


/*************************************************************************
    > File Name: E.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com
    > Created Time: 2019年04月17日 星期三 10时52分04秒
 ************************************************************************/

#include<bits/stdc++.h>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define P pair<int,int>
using namespace std;
const int N = 2E5+10;
int f[N],vc[N];
map<int,P> pos;
bool vis[N];

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
    ios::sync_with_stdio(false); cin.tie(0);
    int n,k,w;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> w;
        vc[w] = i;
        pos[i] = make_pair(i - 1, i + 1);
    }
    for(int i = 1; i <= n + 2; ++i) f[i] = i;
    int cur = 0;
    for(int i = n; i >= 1; --i) {
        if(vis[vc[i]] == 1) continue;
        vis[vc[i]] = 1;
        f[vc[i]] = n + 1 + cur;
        P p = make_pair(n + 2, -2);
        vector<int> t = {vc[i]};

        for(int l = 1, d = 1, x = vc[i] + l; d <= k && x <= n; x = pos[x].second) {
            if(vis[x]) {
                continue;
            }
            p.second = max(x + 1, p.second);
            ++d;
            vis[x] = 1;
            f[x] = n + 1 + cur;
            t.push_back(x);
        }
        for(int r = 1, d = 1, y = vc[i] - r; d <= k && y >= 1; y = pos[y].first) {
            if(vis[y]) {
                continue;
            }
            p.first = min(y - 1, p.first);
            ++d;
            vis[y] = 1;
            f[y] = n + 1 + cur;
            t.push_back(y);
        }
        if(p.first == n + 2) p.first = 0;
        if(p.second == -2) p.second = n + 1;
        for(int i = 0; i < t.size(); ++i) {
            pos[t[i]] = p;
        }
        cur ^= 1;
    }
    for(int i = 1; i <= n; ++i) {
        cout << f[i] - n;
    }
    return 0;
}


/*************************************************************************
    > File Name: E.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com
    > Created Time: 2019年04月17日 星期三 10时52分04秒
 ************************************************************************/

#include<bits/stdc++.h>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define P pair<int,int>
using namespace std;
const int N = 2E5+10;
int f[N],vc[N],a[N];
map<int,P> pos;
bool vis[N];

int getF(int v)
{
    if(f[v] == v) return v;
    return f[v] = getF(f[v]);
}

void mrge(int u,int v)
{
    int p = getF(u);
    int q = getF(v);
    if(p != q) f[p] = q;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
    ios::sync_with_stdio(false); cin.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        vc[a[i]] = i;
        pos[i] = make_pair(i - 1, i + 1);
    }
    for(int i = 1; i <= n + 2; ++i) f[i] = i;
    int cur = 0;
    for(int i = n; i >= 1; --i) {
        if(vis[vc[i]] == 1) continue;
        vis[vc[i]] = 1;

        f[vc[i]] = n + 1 + cur;
        P p = make_pair(n + 2, -2);
        vector<int> t = {vc[i]};

        for(int l = 1, d = 1, x = vc[i] + l; d <= k && x <= n; x = pos[x].second) {
            if(vis[x]) {
            //    l = pos[vc[i] + l].second;
                continue;
            }
            p.second = max(x + 1, p.second);
            ++d;
            vis[x] = 1;
            f[x] = n + 1 + cur;
            t.push_back(x);
        }
        for(int r = 1, d = 1, y = vc[i] - r; d <= k && y >= 1; y = pos[y].first) {
            if(vis[y]) {
            //    r = pos[vc[i] - r].first;
                continue;
            }
            p.first = min(y - 1, p.first);
            ++d;
            vis[y] = 1;
            f[y] = n + 1 + cur;
            t.push_back(y);
        }
        if(p.first == n + 2) p.first = 0;
        if(p.second == -2) p.second = n + 1;
        for(int i = 0; i < t.size(); ++i) {
            pos[t[i]] = p;
        }
        cur ^= 1;
    }
    for(int i = 1; i <= n; ++i) {
        cout << f[i] - n;
    }
    return 0;
}


/*************************************************************************
    > File Name: E.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com
    > Created Time: 2019年04月17日 星期三 10时52分04秒
 ************************************************************************/

#include<bits/stdc++.h>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define P pair<int,int>
using namespace std;
const int N = 2E5+10;
int f[N],vc[N],a[N];
bool vis[N];
int getF(int v)
{
    if(f[v] == v) return v;
    return f[v] = getF(f[v]);
}

void mrge(int u,int v)
{
    int p = getF(u);
    int q = getF(v);
    if(p != q) f[p] = q;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
    ios::sync_with_stdio(false); cin.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        vc[a[i]] = i;
    }
    for(int i = 1; i <= n + 2; ++i) f[i] = i;
    int cur = 0;
    for(int i = n; i >= 1; --i) {
        if(vis[vc[i]] == 1) continue;
        vis[vc[i]] = 1;
        mrge(vc[i], n + 1 + cur);
        for(int l = 1, d = 1; d <= k && vc[i] + l <= n; ++l) {
            if(vis[vc[i] + l]) {
                l += 2 * k;
                continue;
            }
            ++d;
            vis[vc[i] + l] = 1;
            mrge(vc[i] + l, vc[i]);
        }
        for(int r = 1, d = 1; d <= k && vc[i] - r >= 1; ++r) {
            if(vis[vc[i] - r]) {
                r -= 2 * k;
                continue;
            }
            ++d;
            vis[vc[i] - r] = 1;
            mrge(vc[i] - r, vc[i]);
        }
        cur ^= 1;
    }
    for(int i = 1; i <= n; ++i) {
        cout << getF(i) - n;
    }
    return 0;
}


/*************************************************************************
    > File Name: E.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com
    > Created Time: 2019年04月17日 星期三 10时52分04秒
 ************************************************************************/

#include<bits/stdc++.h>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define P pair<int,int>
using namespace std;
const int N = 2E5+10;
int f[N],vc[N],a[N];
bool vis[N];
int getF(int v)
{
    if(f[v] == v) return v;
    return f[v] = getF(f[v]);
}

void mrge(int u,int v)
{
    int p = getF(u);
    int q = getF(v);
    if(p != q) f[p] = q;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
    ios::sync_with_stdio(false); cin.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        vc[a[i]] = i;
    }
    for(int i = 1; i <= n + 2; ++i) f[i] = i;
    int cur = 0;
    for(int i = n; i >= 1; --i) {
        if(vis[vc[i]] == 1) continue;
        vis[vc[i]] = 1;
        mrge(vc[i], n + 1 + cur);
        for(int l = 1, d = 1; d <= k && vc[i] + l <= n; ++l) {
            if(vis[vc[i] + l]) {
                l += 2 * k;
                continue;
            }
            ++d;
            vis[vc[i] + l] = 1;
            mrge(vc[i] + l, vc[i]);
        }
        for(int r = 1, d = 1; d <= k && vc[i] - r >= 1; ++r) {
            if(vis[vc[i] - r]) {
                r += 2 * k;
                continue;
            }
            ++d;
            vis[vc[i] - r] = 1;
            mrge(vc[i] - r, vc[i]);
        }
        cur ^= 1;
    }
    for(int i = 1; i <= n; ++i) {
        cout << getF(i) - n;
    }
    return 0;
}


/*************************************************************************
    > File Name: E.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com
    > Created Time: 2019年04月17日 星期三 10时52分04秒
 ************************************************************************/

#include<bits/stdc++.h>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define P pair<int,int>
using namespace std;
const int N = 2E5+10;
int f[N],vc[N],a[N];
map<int,P> pos;
bool vis[N];

int getF(int v)
{
    if(f[v] == v) return v;
    return f[v] = getF(f[v]);
}

void mrge(int u,int v)
{
    int p = getF(u);
    int q = getF(v);
    if(p != q) f[p] = q;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
    ios::sync_with_stdio(false); cin.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        vc[a[i]] = i;
        pos[i] = make_pair(i - 1, i + 1);
    }
    for(int i = 1; i <= n + 2; ++i) f[i] = i;
    int cur = 0;
    for(int i = n; i >= 1; --i) {
        if(vis[vc[i]] == 1) continue;
        vis[vc[i]] = 1;

        f[vc[i]] = n + 1 + cur;
        P p = make_pair(n + 1, -1);
        vector<int> t = {vc[i]};
        for(int l = 1, d = 1; d <= k && vc[i] + l <= n; ++l) {
            if(vis[vc[i] + l]) {
                l = pos[vc[i] + l].second;
                continue;
            }
            p.second = max(vc[i] + l, p.second);
            ++d;
            vis[vc[i] + l] = 1;
            f[vc[i] + l] = n + 1 + cur;
            t.push_back(vc[i] + l);
        }
        for(int r = 1, d = 1; d <= k && vc[i] - r >= 1; ++r) {
            if(vis[vc[i] - r]) {
                r = pos[vc[i] - r].first;
                continue;
            }
            p.first = min(vc[i] - r, p.first);
            ++d;
            vis[vc[i] - r] = 1;
            f[vc[i] - r] = n + 1 + cur;
            t.push_back(vc[i] - r);
        }
        p.first = min(0,p.first);
        p.second  = max(n, p.second);
        for(int i = 0; i < t.size(); ++i) {
            pos[t[i]] = p;
        }
        cur ^= 1;
    }
    for(int i = 1; i <= n; ++i) {
        cout << f[i] - n;
    }
    return 0;
}


/*************************************************************************
    > File Name: E.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com
    > Created Time: 2019年04月17日 星期三 10时52分04秒
 ************************************************************************/

#include<bits/stdc++.h>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define P pair<int,int>
using namespace std;
const int N = 2E5+10;
int f[N],vc[N],a[N];
bool vis[N];
int getF(int v)
{
    if(f[v] == v) return v;
    return f[v] = getF(f[v]);
}

void mrge(int u,int v)
{
    int p = getF(u);
    int q = getF(v);
    if(p != q) f[p] = q;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
    ios::sync_with_stdio(false); cin.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        vc[a[i]] = i;
    }
    for(int i = 1; i <= n + 2; ++i) f[i] = i;
    int cur = 0;
    for(int i = n; i >= 1; --i) {
        if(vis[vc[i]] == 1) continue;
        vis[vc[i]] = 1;
        f[vc[i]] = n + 1 + cur;
        //mrge(vc[i], n + 1 + cur);
        for(int l = 1, d = 1; d <= k && vc[i] + l <= n; ++l) {
            if(vis[vc[i] + l]) {
                l += 2 * k;
                continue;
            }
            ++d;
            vis[vc[i] + l] = 1;
            f[vc[i] + l] = n + 1 + cur;
   //         mrge(vc[i] + l, vc[i]);
        }
        for(int r = 1, d = 1; d <= k && vc[i] - r >= 1; ++r) {
            if(vis[vc[i] - r]) {
                r += 2 * k;
                continue;
            }
            ++d;
            vis[vc[i] - r] = 1;
            f[vc[i] - r] = n + 1 + cur;
          //  mrge(vc[i] - r, vc[i]);
        }
        cur ^= 1;
    }
    for(int i = 1; i <= n; ++i) {
        cout << f[i] - n;
    }
    return 0;
}


/*************************************************************************
    > File Name: E.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com
    > Created Time: 2019年04月17日 星期三 10时52分04秒
 ************************************************************************/

#include<bits/stdc++.h>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define P pair<int,int>
using namespace std;
const int N = 2E5+10;
int f[N],vc[N],a[N];
bool vis[N];
int getF(int v)
{
    if(f[v] == v) return v;
    return f[v] = getF(f[v]);
}

void mrge(int u,int v)
{
    int p = getF(u);
    int q = getF(v);
    if(p != q) f[p] = q;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
    ios::sync_with_stdio(false); cin.tie(0);
    int n,k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        vc[a[i]] = i;
    }
    for(int i = 1; i <= n + 2; ++i) f[i] = i;
    int cur = 0;
    for(int i = n; i >= 1; --i) {
        if(vis[vc[i]] == 1) continue;
        vis[vc[i]] = 1;
        mrge(vc[i], n + 1 + cur);
        for(int l = 1, d = 1; d <= k && vc[i] + l <= n; ++l) {
            if(vis[vc[i] + l]) {
                l += 2 * k;
                continue;
            }
            ++d;
            vis[vc[i] + l] = 1;
            mrge(vc[i] + l, vc[i]);
        }
        for(int r = 1, d = 1; d <= k && vc[i] - r >= 1; --r) {
            if(vis[vc[i] - r]) {
                r -= 2 * k;
                continue;
            }
            ++d;
            vis[vc[i] - r] = 1;
            mrge(vc[i] - r, vc[i]);
        }
        cur ^= 1;
    }
    for(int i = 1; i <= n; ++i) {
        cout << getF(i) - n << ' ';
    }
    return 0;
}


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

#define ll long long int

struct node
{
    int val,pos;
};

int vis[200007];

bool cmp(node a,node b)
{
    return a.val>b.val;
}

int main()
{
    int n,k,k1,k2;
    cin>>n>>k;
    node arr[n];
    set<int>s;
    s.insert(-1);
    s.insert(-1);
    for(int i=0; i<n; i++)
    {
        cin>>arr[i].val;
        arr[i].pos=i;
        s.insert(i);
    }
    sort(arr,arr+n,cmp);
    bool flag=0;
    for(int i=0; i<n; i++)
    {
        if(!vis[arr[i].pos])
        {
            //cout<<arr[i].pos<<endl;
            if(flag)
            {
                k1=k2=k;
                int te=arr[i].pos;
                auto pos=s.find(te);
                k1++;
                for(auto it=pos;k1&&it!=s.end();it++)
                {
                    vis[*it]=2;
                    //cout<<*it<<" "<<k1<<endl;
                    s.erase(*it);
                    k1--;
                    //it++;
                }
                pos--;
                for(auto it=pos;k2&&*it!=-1;it--)
                {
                    vis[*it]=2;
                    //cout<<*it<<" "<<k2<<endl;
                    s.erase(*it);
                    k2--;
                }
            }
            else
            {
                k1=k2=k;
                int te=arr[i].pos;
                auto pos=s.find(te);
                k1++;
                //cout<<*pos<<endl;
                for(auto it=pos;k1&&it!=s.end();it++)
                {
                    vis[*it]=1;
                    //cout<<*it<<" "<<k1<<endl;
                    s.erase(*it);
                    k1--;
                    //it++;
                }
                pos--;
                //cout<<*pos<<endl;
                for(auto it=pos;k2&&*it!=-1;it--)
                {
                    vis[*it]=1;
                    s.erase(*it);
                    k2--;
                }
            }
            if(flag)
                flag=0;
            else
                flag=1;
        }

    }
    for(int i=0; i<n; i++)
        cout<<vis[i];
    cout<<endl;
    return 0;
}


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

#define ll long long int

struct node
{
    int val,pos;
};

int vis[200007];

bool cmp(node a,node b)
{
    return a.val>b.val;
}

int main()
{
    int n,k,k1,k2,te;
    cin>>n>>k;
    set<int>::iterator it;
    node arr[n];
    set<int>s;
    s.insert(-1);
    for(int i=0; i<n; i++)
    {
        cin>>arr[i].val;
        arr[i].pos=i;
        s.insert(i);
    }
    sort(arr,arr+n,cmp);
    bool flag=0;
    for(int i=0; i<n; i++)
    {
        if(!vis[arr[i].pos])
        {
            cout<<arr[i].pos<<endl;
            if(flag)
            {
                k1=k2=k;
                te=arr[i].pos;
                s.erase(te);
                vis[te]=2;
                //te++;
                for(; k1&&it!=s.end();)
                {
                    it=s.upper_bound(te);
                    if(it==s.end())
                        break;
                    vis[*it]=2;

                    //cout<<*it<<" "<<te<<endl;
                    s.erase(it);
                    k1--;
                    te++;
                }
                te=arr[i].pos;
                for(; k2;)
                {
                    it=s.lower_bound(te);
                    if(*it==-1)
                        break;
                    vis[*it]=2;
                    //cout<<*it<<" "<<te<<endl;
                    s.erase(it);
                    k2--;
                    te--;
                }
            }
            else
            {
                //cout<<arr[i].pos<<endl;
                k1=k2=k;
                te=arr[i].pos;
                s.erase(te);
                vis[te]=1;
//                //te++;
//                for(auto jt=s.begin();jt!=s.end();jt++)
//                    cout<<*jt<<" ";
//                cout<<endl;
                for(; k1&&it!=s.end();)
                {
//                    for(auto jt=s.begin();jt!=s.end();jt++)
//                    cout<<*jt<<" ";
//                cout<<endl;
                    it=s.upper_bound(te);
                    if(it==s.end())
                        break;
                    vis[*it]=1;
                    //cout<<*it<<" "<<te<<endl;
                    s.erase(it);
                    k1--;
                    te++;
                }
                te=arr[i].pos;
                for(; k2;)
                {
//                    for(auto jt=s.begin();jt!=s.end();jt++)
//                    cout<<*jt<<" ";
//                cout<<endl;
                    it=s.lower_bound(te);
                    if(*it==-1)
                        break;
                    vis[*it]=1;

                    //cout<<*it<<" "<<te<<endl;
                    s.erase(it);
                    k2--;
                    te--;
                }
            }
            if(flag)
                flag=0;
            else
                flag=1;
        }

    }
    for(int i=0; i<n; i++)
        cout<<vis[i];
    cout<<endl;
    return 0;
}


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

#define ll long long int

struct node
{
    int val,pos;
};

int vis[200007];

bool cmp(node a,node b)
{
    return a.val>b.val;
}

int main()
{
    int n,k,k1,k2,te;
    cin>>n>>k;
    set<int>::iterator it;
    node arr[n];
    set<int>s;
    s.insert(-1);
    for(int i=0; i<n; i++)
    {
        cin>>arr[i].val;
        arr[i].pos=i;
        s.insert(i);
    }
    sort(arr,arr+n,cmp);
    vector<int>v;
    bool flag=0;
    for(int i=0; i<n; i++)
    {
        if(!vis[arr[i].pos])
        {
            if(flag)
            {
                te=arr[i].pos;
                it=s.find(te);
                for(int j=0;j<=k;j++)
                {
                    if(it==s.end())
                        break;
                    v.push_back(*it);
                    vis[*it]=2;
                    it++;
                }
                it=s.find(te);
                it--;
                for(int j=0;j<k;j++)
                {
                    if(*it==-1)
                        break;
                    v.push_back(*it);
                    vis[*it]=2;
                    it--;
                }
                for(auto x:v)
                {
                    s.erase(x);
                }
            }
            else
            {
                te=arr[i].pos;
                it=s.find(te);
                for(int j=0;j<=k;j++)
                {
                    if(it==s.end())
                        break;
                    v.push_back(*it);
                    vis[*it]=1;
                    it++;
                }
                it=s.find(te);
                it--;
                for(int j=0;j<k;j++)
                {
                    if(*it==-1)
                        break;
                    v.push_back(*it);
                    vis[*it]=1;
                    it--;
                }
                for(auto x:v)
                {
                    s.erase(x);
                }
            }
            if(flag)
                flag=0;
            else
                flag=1;
        }

    }
    int i=0;
    for(i=0; i<n; i++)
    {
        cout<<vis[i];
    }
    cout<<endl;
    return 0;
}


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

#define ll long long int

struct node
{
    int val,pos;
};

int vis[200007];

bool cmp(node a,node b)
{
    return a.val>b.val;
}

int main()
{
    int n,k,k1,k2;
    cin>>n>>k;
    node arr[n];
    set<int>s;
    s.insert(-1);
    s.insert(-1);
    for(int i=0; i<n; i++)
    {
        cin>>arr[i].val;
        arr[i].pos=i;
        s.insert(i);
    }
    sort(arr,arr+n,cmp);
    bool flag=0;
    for(int i=0; i<n; i++)
    {
        if(!vis[arr[i].pos])
        {
            //cout<<arr[i].pos<<endl;
            if(flag)
            {
                k1=k2=k;
                int te=arr[i].pos;
                auto pos=s.find(te);
                k1++;
                for(auto it=pos;k1&&it!=s.end();)
                {
                    vis[*it]=2;
                    //cout<<*it<<" "<<k1<<endl;
                    s.erase(*it);
                    k1--;
                    it++;
                }
                pos--;
                for(auto it=pos;k2&&*it!=-1;it--)
                {
                    vis[*it]=2;
                    //cout<<*it<<" "<<k2<<endl;
                    s.erase(*it);
                    k2--;
                }
            }
            else
            {
                k1=k2=k;
                int te=arr[i].pos;
                auto pos=s.find(te);
                k1++;
                //cout<<*pos<<endl;
                for(auto it=pos;k1&&it!=s.end();)
                {
                    vis[*it]=1;
                    //cout<<*it<<" "<<k1<<endl;
                    s.erase(*it);
                    k1--;
                    it++;
                }
                pos--;
                //cout<<*pos<<endl;
                for(auto it=pos;k2&&*it!=-1;it--)
                {
                    vis[*it]=1;
                    s.erase(*it);
                    k2--;
                }
            }
            if(flag)
                flag=0;
            else
                flag=1;
        }

    }
    for(int i=0; i<n; i++)
        cout<<vis[i];
    cout<<endl;
    return 0;
}


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

#define ll long long int

struct node
{
    int val,pos;
};

int vis[200007];

bool cmp(node a,node b)
{
    return a.val>b.val;
}

int main()
{
    int n,k,k1,k2;
    cin>>n>>k;
    node arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i].val;
        arr[i].pos=i;
    }
    sort(arr,arr+n,cmp);
    bool flag=0;
    for(int i=0; i<n; i++)
    {
        if(!vis[arr[i].pos])
        {
            //cout<<arr[i].pos<<endl;
            if(flag)
            {
                vis[arr[i].pos]=2;
                k1=k2=k;
                int te=arr[i].pos;
                for(int j=1; j<=k1; j++)
                {
                    if(te-j<0)
                        break;
                    if(!vis[te-j])
                    {
                        vis[te-j]=2;
                    }
                    else
                        k1++;
                }
                te=arr[i].pos;
                for(int j=1; j<=k2; j++)
                {
                    if(te+j>=n)
                        break;
                    if(!vis[te+j])
                    {
                        vis[te+j]=2;
                    }
                    else
                        k2++;
                }
            }
            else
            {
                vis[arr[i].pos]=1;
                int te=arr[i].pos;
                k1=k2=k;
                for(int j=1; j<=k1; j++)
                {
                    if(te-j<0)
                        break;
                    if(!vis[te-j])
                    {
                        vis[te-j]=1;
                    }
                    else
                        k1++;
                }
                te=arr[i].pos;
                for(int j=1; j<=k2; j++)
                {
                    if(te+j>=n)
                        break;
                    if(!vis[te+j])
                    {
                        vis[te+j]=1;
                    }
                    else
                        k2++;
                }
            }
            if(flag)
                flag=0;
            else
                flag=1;
        }

    }
    for(int i=0; i<n; i++)
        cout<<vis[i];
    cout<<endl;
    return 0;
}


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

#define ll long long int

struct node
{
    int val,pos;
};

int vis[200007];

bool cmp(node a,node b)
{
    return a.val>b.val;
}

int main()
{
    int n,k;
    cin>>n>>k;
    node arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i].val;
        arr[i].pos=i;
    }
    sort(arr,arr+n,cmp);
    bool flag=0;
    for(int i=0; i<n; i++)
    {
        if(!vis[arr[i].pos])
        {
            //cout<<arr[i].pos<<endl;
            if(flag)
            {
                vis[arr[i].pos]=2;
                int te=arr[i].pos;
                for(int j=0; j<=k; j++)
                {
                    if(te-j>=0&&!vis[te-j])
                    {
                        vis[te-j]=2;
                    }
                    if(te+j<n&&!vis[te+j])
                    {
                        //cout<<te<<" "<<te+j<<endl;
                        vis[te+j]=2;
                    }
                }
            }
            else
            {
                vis[arr[i].pos]=1;
                int te=arr[i].pos;
                for(int j=0; j<=k; j++)
                {
                    if(te-j>=0&&!vis[te-j])
                    {
                        vis[te-j]=1;
                    }
                    if(te+j<n&&!vis[te+j])
                    {
                        //cout<<te<<" "<<te+j<<endl;
                        vis[te+j]=1;
                    }
                }
            }
            if(flag)
                flag=0;
            else
                flag=1;
        }

    }
    for(int i=0; i<n; i++)
        cout<<vis[i];
    cout<<endl;
    return 0;
}


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

#define ll long long int

struct node
{
    int val,pos;
};

int vis[200007];

bool cmp(node a,node b)
{
    return a.val>b.val;
}

int main()
{
    int n,k,k1,k2,te;
    cin>>n>>k;
    set<int>::iterator it;
    node arr[n];
    set<int>s;
    s.insert(-1);
    for(int i=0; i<n; i++)
    {
        cin>>arr[i].val;
        arr[i].pos=i;
        s.insert(i);
    }
    sort(arr,arr+n,cmp);
    vector<int>v;
    int flag=0;
    for(int i=0; i<n; i++)
    {
        if(!vis[arr[i].pos])
        {
            te=arr[i].pos;
            it=s.find(te);
            for(int j=0; j<=k; j++)
            {
                if(it==s.end())
                    break;
                v.push_back(*it);
                it++;
            }
            it=s.find(te);
            it--;
            for(int j=0; j<k; j++)
            {
                if(*it==-1)
                    break;
                v.push_back(*it);
                it--;
            }
            for(auto x:v)
            {
                vis[x]=1+flag;
                s.erase(x);
                v.pop_back();
            }
            if(flag)
                flag=0;
            else
                flag=1;
        }

    }
    int i=0;
    for(i=0; i<n; i++)
    {
        cout<<vis[i];
    }
    cout<<endl;
    return 0;
}


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

#define ll long long int

struct node
{
    int val,pos;
};

int vis[200007];

bool cmp(node a,node b)
{
    return a.val>b.val;
}

int main()
{
    int n,k,k1,k2,te;
    cin>>n>>k;
    set<int>::iterator it;
    node arr[n];
    set<int>s;
    s.insert(-1);
    for(int i=0; i<n; i++)
    {
        cin>>arr[i].val;
        arr[i].pos=i;
        s.insert(i);
    }
    sort(arr,arr+n,cmp);
    vector<int>v;
    bool flag=0;
    for(int i=0; i<n; i++)
    {
        if(!vis[arr[i].pos])
        {
            if(flag)
            {
                te=arr[i].pos;
                it=s.find(te);
                for(int i=0;i<=k;i++)
                {
                    if(it==s.end())
                        break;
                    v.push_back(*it);
                    vis[*it]=2;
                    it++;
                }
                it=s.find(te);
                it--;
                for(int i=0;i<k;i++)
                {
                    if(*it==-1)
                        break;
                    v.push_back(*it);
                    vis[*it]=2;
                    it--;
                }
                for(auto x:v)
                {
                    s.erase(x);
                }
            }
            else
            {
                te=arr[i].pos;
                it=s.find(te);
                for(int i=0;i<=k;i++)
                {
                    if(it==s.end())
                        break;
                    v.push_back(*it);
                    vis[*it]=1;
                    it++;
                }
                it=s.find(te);
                it--;
                for(int i=0;i<k;i++)
                {
                    if(*it==-1)
                        break;
                    v.push_back(*it);
                    vis[*it]=1;
                    it--;
                }
                for(auto x:v)
                {
                    s.erase(x);
                }
            }
            if(flag)
                flag=0;
            else
                flag=1;
        }

    }
    int i=0;
    for(i=0; i<n; i++)
    {
        cout<<vis[i];
    }
    cout<<endl;
    return 0;
}


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

#define ll long long int

struct node
{
    int val,pos;
};

int vis[200007];

bool cmp(node a,node b)
{
    return a.val>b.val;
}

int main()
{
    int n,k,k1,k2;
    cin>>n>>k;
    node arr[n];
    set<int>s;
    s.insert(-1);
    s.insert(-1);
    for(int i=0; i<n; i++)
    {
        cin>>arr[i].val;
        arr[i].pos=i;
        s.insert(i);
    }
    sort(arr,arr+n,cmp);
    bool flag=0;
    for(int i=0; i<n; i++)
    {
        if(!vis[arr[i].pos])
        {
            //cout<<arr[i].pos<<endl;
            if(flag)
            {
                k1=k2=k;
                int te=arr[i].pos;
                auto pos=s.find(te);
                k1++;
                for(auto it=pos;k1&&it!=s.end();it++)
                {
                    vis[*it]=2;
                    //cout<<*it<<" "<<k1<<endl;
                    s.erase(*it);
                    k1--;
                    it++;
                }
                pos--;
                for(auto it=pos;k2&&*it!=-1;it--)
                {
                    vis[*it]=2;
                    //cout<<*it<<" "<<k2<<endl;
                    s.erase(*it);
                    k2--;
                }
            }
            else
            {
                k1=k2=k;
                int te=arr[i].pos;
                auto pos=s.find(te);
                k1++;
                //cout<<*pos<<endl;
                for(auto it=pos;k1&&it!=s.end();it++)
                {
                    vis[*it]=1;
                    //cout<<*it<<" "<<k1<<endl;
                    s.erase(*it);
                    k1--;
                    it++;
                }
                pos--;
                //cout<<*pos<<endl;
                for(auto it=pos;k2&&*it!=-1;it--)
                {
                    vis[*it]=1;
                    s.erase(*it);
                    k2--;
                }
            }
            if(flag)
                flag=0;
            else
                flag=1;
        }

    }
    for(int i=0; i<n; i++)
        cout<<vis[i];
    cout<<endl;
    return 0;
}


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

#define ll long long int

struct node
{
    int val,pos;
};

int vis[200007];

bool cmp(node a,node b)
{
    return a.val>b.val;
}

int main()
{
    int n,k,k1,k2,te;
    cin>>n>>k;
    set<int>::iterator it;
    node arr[n];
    set<int>s;
    s.insert(-1);
    for(int i=0; i<n; i++)
    {
        cin>>arr[i].val;
        arr[i].pos=i;
        s.insert(i);
    }
    sort(arr,arr+n,cmp);
    bool flag=0;
    for(int i=0; i<n; i++)
    {
        if(!vis[arr[i].pos])
        {
            //cout<<arr[i].pos<<endl;
            if(flag)
            {
                k1=k2=k;
                te=arr[i].pos;
                s.erase(te);
                vis[te]=2;
                te++;
                for(; k1&&it!=s.end();)
                {
                    it=s.upper_bound(te);
                    vis[*it]=2;
                    //cout<<*it<<" "<<te<<endl;
                    s.erase(it);
                    k1--;
                    te++;
                }
                te=arr[i].pos-1;
                for(; k2;)
                {
                    it=s.lower_bound(te);
                    if(*it==-1)
                        break;
                    vis[*it]=2;
                    //cout<<*it<<" "<<te<<endl;
                    s.erase(it);
                    k2--;
                    te--;
                }
            }
            else
            {
                //cout<<arr[i].pos<<endl;
                k1=k2=k;
                te=arr[i].pos;
                s.erase(te);
                vis[te]=1;
//                //te++;
//                for(auto jt=s.begin();jt!=s.end();jt++)
//                    cout<<*jt<<" ";
//                cout<<endl;
                for(; k1&&it!=s.end();)
                {
//                    for(auto jt=s.begin();jt!=s.end();jt++)
//                    cout<<*jt<<" ";
//                cout<<endl;
                    it=s.upper_bound(te);
                    vis[*it]=1;
                    //cout<<*it<<" "<<te<<endl;
                    s.erase(it);
                    k1--;
                    te++;
                }
                te=arr[i].pos-1;
                for(; k2;)
                {
//                    for(auto jt=s.begin();jt!=s.end();jt++)
//                    cout<<*jt<<" ";
//                cout<<endl;
                    it=s.lower_bound(te);
                    vis[*it]=1;
                    if(*it==-1)
                        break;
                    //cout<<*it<<" "<<te<<endl;
                    s.erase(it);
                    k2--;
                    te--;
                }
            }
            if(flag)
                flag=0;
            else
                flag=1;
        }

    }
    for(int i=0; i<n; i++)
        cout<<vis[i];
    cout<<endl;
    return 0;
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <map>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// val, idx
map<int, int> mp;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n), nxt(n), prev(n);
    rep (i, n) {
        cin >> a[i];
        mp.insert({a[i], i});
        nxt[i] = i+1;
        prev[i] = i-1;
    }
    // (*mp.rbegin()).first

    for (int t = 1;; ++t) {
        if (mp.empty()) break;
        auto maxx = (*mp.rbegin());
        b[maxx.second] = t%2==1 ? 1 : 2;
        mp.erase(maxx.first);
        if (prev[maxx.second] >= 0) nxt[prev[maxx.second]] = nxt[maxx.second];
        if (nxt[maxx.second] < n) prev[nxt[maxx.second]] = prev[maxx.second];

        // right
        int curr_r = 0, right;
        for (right = nxt[maxx.second]; curr_r < k && right < n && right >= 0; right = nxt[right]) {
            mp.erase(a[right]);
            curr_r++;
            b[right] = t%2==1 ? 1 : 2;
        }

        // left
        int curr_l = 0, left;
        for (left = prev[maxx.second]; curr_l < k && left >= 0 && left < n; left = prev[left]) {
            mp.erase(a[left]);
            curr_l++;
            b[left] = t%2==1 ? 1 : 2;
        }
        if (left >= 0) nxt[left] = right;
        if (right < n) prev[right] = left;
    }
    for (int x : b)
        cout << x;
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <map>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// val, idx
map<int, int> mp;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n), nxt(n), prev(n);
    rep (i, n) {
        cin >> a[i];
        mp.insert({a[i], i});
        nxt[i] = i+1;
        prev[i] = i-1;
    }
    // (*mp.rbegin()).first

    for (int t = 1;; ++t) {
        if (mp.empty()) break;
        auto maxx = (*mp.rbegin());
        b[maxx.second] = t%2==1 ? 1 : 2;
        mp.erase(maxx.first);
        nxt[prev[maxx.second]] = nxt[maxx.second];
        prev[nxt[maxx.second]] = prev[maxx.second];

        // right
        int curr_r = 0, right;
        for (right = nxt[maxx.second]; curr_r < k && right < a.size(); right = nxt[right]) {
            mp.erase(a[right]);
            curr_r++;
            b[right] = t%2==1 ? 1 : 2;
        }

        // left
        int curr_l = 0, left;
        for (left = prev[maxx.second]; curr_l < k && left >= 0; left = prev[left]) {
            mp.erase(a[left]);
            curr_l++;
            b[left] = t%2==1 ? 1 : 2;
        }
        if (left >= 0) nxt[left] = right;
        if (right < n) prev[right] = left;
    }
    for (int x : b) cout << x;
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <map>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    map<int, int> val_pos;
    map<int, int> pos_val;
    rep (i, n) {
        cin >> a[i];
        val_pos[a[i]] = i;
        pos_val[i] = a[i];
    }

    for (int t = 0; !pos_val.empty(); ++t) {
        auto maxx = val_pos.rbegin();
        auto itr = pos_val.find(maxx->second), itl = pos_val.find(maxx->second);;
        for (int i = 0; i <= k; i++) {
            if (itr == pos_val.end()) break;
            b[itr->first] = t%2+1;
            val_pos.erase(itr->second);
            itr++;
        }
        for (int i = 0; i <= k; i++) {
            if (itl == pos_val.begin()) break;
            b[itl->first] = t%2+1;
            val_pos.erase(itl->second);
            itl--;
        }
        b[maxx->second] = t%2+1;
        val_pos.erase(itl->second);
        pos_val.erase(itl, itr);
    }
    for (int x : b) cout << x;
    cout << endl;
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <map>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    map<int, int> val_pos;
    map<int, int> pos_val;
    rep (i, n) {
        cin >> a[i];
        val_pos[a[i]] = i;
        pos_val[i] = a[i];
    }

    for (int t = 0; !val_pos.empty(); ++t) {
        auto maxx = val_pos.rbegin();
        auto it = pos_val.find(maxx->second);
        for (int i = 0; i < k; i++) {
            auto jt = next(it);
            if (jt == pos_val.end()) break;
            b[jt->first] = t%2+1;
            val_pos.erase(jt->second);
            pos_val.erase(jt);
        }
        it = pos_val.find(maxx->second);
        for (int i = 0; i < k; i++) {
            if (it == pos_val.begin()) break;
            auto jt = prev(it);
            b[jt->first] = t%2+1;
            val_pos.erase(jt->second);
            pos_val.erase(jt);
        }
        b[maxx->second] = t%2+1;
        pos_val.erase(maxx->second);
        val_pos.erase(maxx->first);
    }
    for (int x : b) cout << x;
    cout << endl;
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <map>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    map<int, int> val_pos;
    map<int, int> pos_val;
    rep (i, n) {
        cin >> a[i];
        val_pos[a[i]] = i;
        pos_val[i] = a[i];
    }

    for (int t = 0; !pos_val.empty(); ++t) {
        auto maxx = val_pos.rbegin();
        auto itr = pos_val.find(maxx->second), itl = pos_val.find(maxx->second);

        for (int i = 0; i < k; i++) {
            if (itl == pos_val.begin()) break;
            itl--;
            b[itl->first] = t%2+1;
            val_pos.erase(itl->second);
        }

        for (int i = 0; i < k+1; i++) {
            b[itr->first] = t%2+1;
            val_pos.erase(itr->second);
            itr++;
            if (itr == pos_val.end()) break;
        }

        pos_val.erase(itl, itr);
    }
    for (int x : b) cout << x;
    cout << endl;
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <map>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// val, idx
map<int, int> mp;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n), nxt(n), prev(n);
    rep (i, n) {
        cin >> a[i];
        mp.insert({a[i], i});
        nxt[i] = i+1;
        prev[i] = i-1;
    }
    // (*mp.rbegin()).first

    for (int t = 1;; ++t) {
        if (mp.empty()) break;
        auto maxx = (*mp.rbegin());
        b[maxx.second] = t%2==1 ? 1 : 2;
        mp.erase(maxx.first);
        nxt[prev[maxx.second]] = nxt[maxx.second];
        prev[nxt[maxx.second]] = prev[maxx.second];

        // right
        int curr_r = 0, right;
        for (right = nxt[maxx.second]; curr_r < k && right < n && right >= 0; right = nxt[right]) {
            mp.erase(a[right]);
            curr_r++;
            b[right] = t%2==1 ? 1 : 2;
        }

        // left
        int curr_l = 0, left;
        for (left = prev[maxx.second]; curr_l < k && left >= 0 && left < n; left = prev[left]) {
            mp.erase(a[left]);
            curr_l++;
            b[left] = t%2==1 ? 1 : 2;
        }
        if (left >= 0) nxt[left] = right;
        if (right < n) prev[right] = left;
    }
    for (int x : b)
        cout << x;
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <map>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// val, idx
map<int, int> mp;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n);
    vector<int> b(n);
    rep (i, n) {
        cin >> a[i];
        mp.insert({a[i], i});
    }
    // (*mp.rbegin()).first

    int erased = 0;
    for (int t = 1;; ++t) {
        if (mp.empty()) break;
        if (erased == n) break;
        auto maxx = (*mp.rbegin());
        a[maxx.second] = -1;
        b[maxx.second] = t%2==1 ? 1 : 2;
        mp.erase(maxx.first);
        erased++;

        // right
        int curr_r = 0;
        for (int i = maxx.second + 1; curr_r < k && i < a.size(); ++i) {
            if (a[i] == -1) continue;
            mp.erase(a[i]);
            curr_r++;
            b[i] = t%2==1 ? 1 : 2;
            a[i] = -1;
            erased++;
        }

        // left
        int curr_l = 0;
        for (int i = maxx.second - 1; curr_l < k && i >= 0; --i) {
            if (a[i] == -1) continue;
            mp.erase(a[i]);
            curr_l++;
            b[i] = t%2==1 ? 1 : 2;
            a[i] = -1;
            erased++;
        }
    }
    for (int x : b) cout << x;
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <map>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    map<int, int> val_pos;
    map<int, int> pos_val;
    rep (i, n) {
        cin >> a[i];
        val_pos[a[i]] = i;
        pos_val[i] = a[i];
    }

    for (int t = 0; !val_pos.empty(); ++t) {
        auto maxx = val_pos.rbegin();
        auto it = pos_val.find(maxx->second);
        for (int i = 0; i < k; i++) {
            auto jt = next(it);
            if (it == pos_val.end() || jt == pos_val.end()) break;
            b[jt->first] = t%2+1;
            val_pos.erase(jt->second);
            pos_val.erase(jt);
        }
        it = pos_val.find(maxx->second);
        for (int i = 0; i < k; i++) {
            auto jt = prev(it);
            if (it == pos_val.begin() || jt == pos_val.begin()) break;
            b[jt->first] = t%2+1;
            val_pos.erase(jt->second);
            pos_val.erase(jt);
        }
        b[maxx->second] = t%2+1;
        pos_val.erase(maxx->second);
        val_pos.erase(maxx->first);
    }
    for (int x : b) cout << x;
    cout << endl;
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <map>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// val, idx
map<int, int> mp;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n), nxt(n), prev(n);
    rep (i, n) {
        cin >> a[i];
        mp.insert({a[i], i});
        nxt[i] = i+1;
        prev[i] = i-1;
    }
    // (*mp.rbegin()).first

    for (int t = 1;; ++t) {
        if (mp.empty()) break;
        auto maxx = (*mp.rbegin());
        b[maxx.second] = t%2==1 ? 1 : 2;
        mp.erase(maxx.first);
        if (prev[maxx.second] >= 0) nxt[prev[maxx.second]] = nxt[maxx.second];
        if (nxt[maxx.second] < n) prev[nxt[maxx.second]] = prev[maxx.second];

        // right
        int curr_r = 0, right;
        for (right = nxt[maxx.second]; curr_r < k && right < n; right = nxt[right]) {
            mp.erase(a[right]);
            curr_r++;
            b[right] = t%2==1 ? 1 : 2;
        }

        // left
        int curr_l = 0, left;
        for (left = prev[maxx.second]; curr_l < k && left >= 0; left = prev[left]) {
            mp.erase(a[left]);
            curr_l++;
            b[left] = t%2==1 ? 1 : 2;
        }
        if (left >= 0) nxt[left] = right;
        if (right < n) prev[right] = left;
    }
    for (int x : b)
        cout << x;
}


#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <map>

#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    map<int, int> val_pos;
    map<int, int> pos_val;
    rep (i, n) {
        cin >> a[i];
        val_pos[a[i]] = i;
        pos_val[i] = a[i];
    }

    for (int t = 0; !val_pos.empty(); ++t) {
        auto maxx = val_pos.rbegin();
        auto it = pos_val.find(maxx->second);

        for (int i = 0; i < k; i++) {
            if (it == pos_val.begin()) break;
            --it;
            b[it->first] = t%2+1;
            val_pos.erase(it->second);
            it = pos_val.erase(it);
        }

        it = pos_val.find(maxx->second);
        for (int i = 0; i < k+1; i++) {
            if (it == pos_val.end()) break;
            b[it->first] = t%2+1;
            val_pos.erase(it->second);
            it = pos_val.erase(it);
        }
    }
    for (int x : b) cout << x;
    cout << endl;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
    int n, k; // 1 <= k <= n <= 2e5
    scanf("%d%d", &n, &k);
    vector<int> a(n); // ai 1 n
    int pre[n], nxt[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; i++){
        if(i - 1 >= 0){
            pre[i] = i - 1;
        }else{
            pre[i] = -1;
        }
        if(i + 1 < n){
            nxt[i] = i + 1;
        }else{
            nxt[i] = -1;
        }
    }
    vector<pair<int, int> > p(n);
    for(int i = 0; i < n; i++){
        p[i] = make_pair(a[i], i);
    }
    sort(p.begin(), p.end());
    vector<int> b2a(n + 1);
    for(int i = 0; i < n; i++){
        b2a[i] = p[i].second;
    }
    int pos = n - 1;
    int team = 1;
    while(pos >= 0){
        // find max
        while(pos >= 0 && a[b2a[pos]] < 0){
            pos --;
        }
        if(pos < 0){
            break;
        }
        int id = b2a[pos];
        a[id] = -team;
        int cnt = k; // > 0
        int start = nxt[id];
        int rmax = id;
        for(int i = start; i >= 0; i = nxt[i]){
            if(a[i] < 0 || cnt == 0){
                break;
            }else{
                a[i] = -team;
                cnt--;
                rmax = i;
            }
        }
        if(rmax + 1 < n){
            rmax ++;
        }else{
            rmax = -1;
        }

        cnt = k; // > 0
        start = pre[id];
        int lmin = id;
        for(int i = start; i >= 0; i = pre[i]){
            if(a[i] < 0 || cnt == 0){
                break;
            }else{
                a[i] = -team;
                cnt --;
                lmin = i;
            }
        }
        if(lmin == 0){
            lmin = -1;
        }else{
            lmin --;
        }

        if(lmin == -1 && rmax == -1){
            break;
        }else{
            if(lmin != -1){
                nxt[lmin] = rmax;
            }
            // at least one of lmin or rmax is not -1. may both != -1
            if(rmax != -1){
                pre[rmax] = lmin;
            }
        }

        team = 1 + team % 2;
    }
    for(int i = 0; i < n; i++){
        printf("%d", -a[i]);
    }
    puts("");

    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <list>
#include <map>

using namespace std;

int main(int argc, char **argv)
{
    int n, k; // 1 <= k <= n <= 2e5
    scanf("%d%d", &n, &k);
    vector<int> a(n); // ai 1 n
    list<int> lst;
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    map<int, list<int>::iterator> mp;
    for(int i = 0; i < n; i++){
        lst.push_back(i);
        mp[i] = --lst.end();
    }

    vector<pair<int, int> > p(n);
    for(int i = 0; i < n; i++){
        p[i] = make_pair(a[i], i);
    }
    sort(p.begin(), p.end());
    vector<int> b2a(n);
    for(int i = 0; i < n; i++){
        b2a[i] = p[i].second;
    }

    int pos = n - 1;
    int team = 1;
    while(pos >= 0){
        // find max
        while(pos >= 0 && a[b2a[pos]] < 0){
            pos --;
        }
        if(pos < 0){
            break;
        }
        int id = b2a[pos--];
        a[id] = -team;

        int cnt = k; // > 0
        list<int>::iterator mit = mp[id], it = mit, rit = mit, lit = mit;
        while((++it) != lst.end() && cnt--){
            a[*it] = -team;
            rit = it;
        }
        rit ++; // not end

        cnt = k; // > 0
        it = mit;
        while(cnt --){
            if(it == lst.begin()){
                break;
            }
            --it;
            a[*it] = -team;
            lit = it;
        }
        // lit must be valid
        lst.erase(lit, rit);
        team = 1 + team % 2;
    }

    for(int i = 0; i < n; i++){
        printf("%d", -a[i]);
    }
    puts("");

    return 0;
}


#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
    int n, k; // 1 <= k <= n <= 2e5
    scanf("%d%d", &n, &k);
    vector<int> a(n); // ai 1 n
    vector<int> pre(n), nxt(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; i++){
        if(i - 1 >= 0){
            pre[i] = i - 1;
        }else{
            pre[i] = -1;
        }
        if(i + 1 < n){
            nxt[i] = i + 1;
        }else{
            nxt[i] = -1;
        }
    }
    vector<pair<int, int> > p(n);
    for(int i = 0; i < n; i++){
        p[i] = make_pair(a[i], i);
    }
    sort(p.begin(), p.end());
    vector<int> b2a(n);
    for(int i = 0; i < n; i++){
        b2a[i] = p[i].second;
    }
    int pos = n - 1;
    int team = 1;
    while(pos >= 0){
        // find max
        while(pos >= 0 && a[b2a[pos]] < 0){
            pos --;
        }
        if(pos < 0){
            break;
        }
        int id = b2a[pos--];
        a[id] = -team;
        int cnt = k; // > 0
        int start = nxt[id];
        int rmax = id;
        for(int i = start; i >= 0 && cnt > 0; i = nxt[i]){
            a[i] = -team;
            cnt--;
            rmax = i;
        }
        rmax = nxt[rmax]; // not rmax + 1 or nxt[rmax + 1]. it is nxt[rmax]. right rmax is in [0, n - 1](start with id).

        cnt = k; // > 0
        start = pre[id];
        int lmin = id;
        for(int i = start; i >= 0 && cnt > 0; i = pre[i]){
            a[i] = -team;
            cnt --;
            lmin = i;
        }
        lmin = pre[lmin]; // left lmin in [0, n - 1] (start with id)

        if(lmin == -1 && rmax == -1){
            break;
        }else{
            if(lmin != -1){
                nxt[lmin] = rmax;
            }
            // at least one of lmin or rmax is not -1. may both != -1
            if(rmax != -1){
                pre[rmax] = lmin;
            }
        }

        team = 1 + team % 2;
    }
    for(int i = 0; i < n; i++){
        printf("%d", -a[i]);
    }
    puts("");

    return 0;
}


#include <cstdio>
#include <vector>

using namespace std;

int main(int argc, char **argv)
{
    int n, b, A; // 1 2e5
    scanf("%d%d%d", &n, &b, &A);
    vector<int> s(n);
    for(int i = 0; i < n; i ++){
        scanf("%1d", &s[i]); // 0 or 1
    }

    int res = 0; // <= n <= 2e5
    int a = A; // both b and a were changed already?
    for(int i = 0; i < n; i++){
        //start or i - 1 to i.
        //in
        if(s[i]){
            if(a < A && b > 0){
                b--;
                a++;
            }else{
                if(a > 0){
                    a--;
                }else if(b > 0){
                    b--; // a == 0 && b > 0 && (a == A (> 0) || b == 0) impossible
                }else{
                    break;
                }
            }
        }else{
            // use a if possible since it can be increased later.
            if(a > 0){
                a--;
            }else if(b > 0){
                b--;
            }else{
                break;
            }
        }

        // enter i
        res ++;
    }

    printf("%d\n", res);

    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
    int n, k; // 1 <= k <= n <= 2e5
    scanf("%d%d", &n, &k);
    vector<int> a(n); // ai 1 n
    vector<int> pre(n), nxt(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; i++){
        if(i - 1 >= 0){
            pre[i] = i - 1;
        }else{
            pre[i] = -1;
        }
        if(i + 1 < n){
            nxt[i] = i + 1;
        }else{
            nxt[i] = -1;
        }
    }
    vector<pair<int, int> > p(n);
    for(int i = 0; i < n; i++){
        p[i] = make_pair(a[i], i);
    }
    sort(p.begin(), p.end());
    vector<int> b2a(n);
    for(int i = 0; i < n; i++){
        b2a[i] = p[i].second;
    }
    int pos = n - 1;
    int team = 1;
    while(pos >= 0){
        // find max
        while(pos >= 0 && a[b2a[pos]] < 0){
            pos --;
        }
        if(pos < 0){
            break;
        }
        int id = b2a[pos--];
        a[id] = -team;
        int cnt = k; // > 0
        int start = nxt[id];
        int rmax = id;
        for(int i = start; i >= 0; i = nxt[i]){
            if(cnt == 0){
                break;
            }else{
                a[i] = -team;
                cnt--;
                rmax = i;
            }
        }
        rmax = nxt[rmax]; // not rmax + 1 or nxt[rmax + 1]. it is nxt[rmax]. right rmax is in [0, n - 1](start with id).

        cnt = k; // > 0
        start = pre[id];
        int lmin = id;
        for(int i = start; i >= 0; i = pre[i]){
            if(cnt == 0){
                break;
            }else{
                a[i] = -team;
                cnt --;
                lmin = i;
            }
        }
        lmin = pre[lmin]; // left lmin in [0, n - 1] (start with id)

        if(lmin == -1 && rmax == -1){
            break;
        }else{
            if(lmin != -1){
                nxt[lmin] = rmax;
            }
            // at least one of lmin or rmax is not -1. may both != -1
            if(rmax != -1){
                pre[rmax] = lmin;
            }
        }

        team = 1 + team % 2;
    }
    for(int i = 0; i < n; i++){
        printf("%d", -a[i]);
    }
    puts("");

    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <list>

using namespace std;

int main(int argc, char **argv)
{
    int n, k; // 1 <= k <= n <= 2e5
    scanf("%d%d", &n, &k);
    vector<int> a(n); // ai 1 n
    list<int> lst;
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    vector<list<int>::iterator> mp(n);
    for(int i = 0; i < n; i++){
        lst.push_back(i);
        mp[i] = --lst.end();
    }

    vector<pair<int, int> > p(n);
    for(int i = 0; i < n; i++){
        p[i] = make_pair(a[i], i);
    }
    sort(p.begin(), p.end());

    vector<int> b2a(n);
    for(int i = 0; i < n; i++){
        b2a[i] = p[i].second;
    }

    int pos = n - 1;
    int team = 1;
    while(pos >= 0){
        // find max
        while(pos >= 0 && a[b2a[pos]] < 0){
            pos --;
        }
        if(pos < 0){
            break;
        }
        int id = b2a[pos--];
        a[id] = -team;

        int cnt = k; // > 0
        list<int>::iterator mit = mp[id], it = mit, rit = mit, lit = mit;
        while((++it) != lst.end() && cnt--){
            a[*it] = -team;
            rit = it;
        }
        rit ++; // not end

        cnt = k; // > 0
        it = mit;
        while(cnt --){
            if(it == lst.begin()){
                break;
            }
            --it;
            a[*it] = -team;
            lit = it;
        }
        // lit must be valid
        lst.erase(lit, rit);
        team = 1 + team % 2;
    }

    for(int i = 0; i < n; i++){
        printf("%d", -a[i]);
    }
    puts("");

    return 0;
}


#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <list>

using namespace std;

int main(int argc, char **argv)
{
    int n, k; // 1 <= k <= n <= 2e5
    scanf("%d%d", &n, &k);
    vector<int> a(n); // ai 1 n
    list<int> lst;
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    vector<list<int>::iterator> mp(n);
    for(int i = 0; i < n; i++){
        lst.push_back(i);
        mp[i] = --lst.end();
    }
    vector<pair<int, int> > p(n);
    for(int i = 0; i < n; i++){
        p[i] = make_pair(a[i], i);
    }
    sort(p.begin(), p.end());
    vector<int> b2a(n);
    for(int i = 0; i < n; i++){
        b2a[i] = p[i].second;
    }
    int pos = n - 1;
    int team = 1;
    while(pos >= 0){
        // find max
        while(pos >= 0 && a[b2a[pos]] < 0){
            pos --;
        }
        if(pos < 0){
            break;
        }
        int id = b2a[pos--];
        a[id] = -team;

        int cnt = k; // > 0
        list<int>::iterator mit = mp[id], it = mit, rit = mit, lit = mit;
        while((++it) != lst.end() && cnt--){
            a[*it] = -team;
            rit = it;
        }
        rit ++; // must not be end before ++

        cnt = k; // > 0
        it = mit;
        while(cnt --){
            if(it == lst.begin()){
                break;
            }
            --it;
            a[*it] = -team;
            lit = it;
        }
        lst.erase(lit, rit); // lit must be valid
        team = 1 + team % 2;
    }

    for(int i = 0; i < n; i++){
        printf("%d", -a[i]);
    }
    puts("");

    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
    int n, k; // 1 <= k <= n <= 2e5
    scanf("%d%d", &n, &k);
    vector<int> a(n); // ai 1 n
    int pre[n], nxt[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; i++){
        if(i - 1 >= 0){
            pre[i] = i - 1;
        }else{
            pre[i] = -1;
        }
        if(i + 1 < n){
            nxt[i] = i + 1;
        }else{
            nxt[i] = -1;
        }
    }
    vector<pair<int, int> > p(n);
    for(int i = 0; i < n; i++){
        p[i] = make_pair(a[i], i);
    }
    sort(p.begin(), p.end());
    vector<int> b2a(n + 1);
    for(int i = 0; i < n; i++){
        b2a[i] = p[i].second;
    }
    int pos = n - 1;
    int team = 1;
    while(pos >= 0){
        // find max
        while(pos >= 0 && a[b2a[pos]] < 0){
            pos --;
        }
        if(pos < 0){
            break;
        }
        int id = b2a[pos--];
        a[id] = -team;
        int cnt = k; // > 0
        int start = nxt[id];
        int rmax = id;
        for(int i = start; i >= 0; i = nxt[i]){
            if(a[i] < 0 || cnt == 0){
                break;
            }else{
                a[i] = -team;
                cnt--;
                rmax = i;
            }
        }
        if(rmax + 1 < n){
            rmax ++;
        }else{
            rmax = -1;
        }

        cnt = k; // > 0
        start = pre[id];
        int lmin = id;
        for(int i = start; i >= 0; i = pre[i]){
            if(a[i] < 0 || cnt == 0){
                break;
            }else{
                a[i] = -team;
                cnt --;
                lmin = i;
            }
        }
        if(lmin == 0){
            lmin = -1;
        }else{
            lmin --;
        }

        if(lmin == -1 && rmax == -1){
            break;
        }else{
            if(lmin != -1){
                nxt[lmin] = rmax;
            }
            // at least one of lmin or rmax is not -1. may both != -1
            if(rmax != -1){
                pre[rmax] = lmin;
            }
        }

        team = 1 + team % 2;
    }
    for(int i = 0; i < n; i++){
        printf("%d", -a[i]);
    }
    puts("");

    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
    int n, k; // 1 <= k <= n <= 2e5
    scanf("%d%d", &n, &k);
    vector<int> a(n); // ai 1 n
    vector<int> pre(n), nxt(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; i++){
        if(i - 1 >= 0){
            pre[i] = i - 1;
        }else{
            pre[i] = -1;
        }
        if(i + 1 < n){
            nxt[i] = i + 1;
        }else{
            nxt[i] = -1;
        }
    }
    vector<pair<int, int> > p(n);
    for(int i = 0; i < n; i++){
        p[i] = make_pair(a[i], i);
    }
    sort(p.begin(), p.end());
    vector<int> b2a(n);
    for(int i = 0; i < n; i++){
        b2a[i] = p[i].second;
    }
    int pos = n - 1;
    int team = 1;
    while(pos >= 0){
        // find max
        while(pos >= 0 && a[b2a[pos]] < 0){
            pos --;
        }
        if(pos < 0){
            break;
        }
        int id = b2a[pos--];
        a[id] = -team;
        int cnt = k; // > 0
        int start = nxt[id];
        int rmax = id;
        for(int i = start; i >= 0 && cnt > 0; i = nxt[i]){
            a[i] = -team;
            cnt--;
            rmax = i;
        }
        rmax = nxt[rmax]; // not rmax + 1 or nxt[rmax + 1]. it is nxt[rmax]. right rmax is in [0, n - 1](start with id).

        cnt = k; // > 0
        start = pre[id];
        int lmin = id;
        for(int i = start; i >= 0 && cnt > 0; i = pre[i]){
            a[i] = -team;
            cnt --;
            lmin = i;
        }
        lmin = pre[lmin]; // left lmin in [0, n - 1] (start with id)

        if(lmin == -1 && rmax == -1){
            break;
        }else{
            if(lmin != -1){
                nxt[lmin] = rmax;
            }
            // at least one of lmin or rmax is not -1. may both != -1
            if(rmax != -1){
                pre[rmax] = lmin;
            }
        }

        team = 1 + team % 2;
    }
    for(int i = 0; i < n; i++){
        printf("%d", -a[i]);
    }
    puts("");

    return 0;
}


#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define vi vector<int>
#define vl vector<ll>
#define ii pair<ll, ll>
#define vii vector<ii>
#define PIii double PPPPPP = 3.14159265358979323846;
#define pb push_back
using namespace std;
const int N = 2e5 + 5;
bool taken[N];
int vis[101];
int pos[N];
set<int> ss;
void solve()
{
    int n,k;
    cin>>n>>k;
    vi v(n),vv(n),ans(n);
    for(int i=0;i<n;++i){
        cin>>v[i];
        pos[v[i]]=i;
    }
    vv=v;
    sort(all(vv));
    int kk=1,last=n-1;
    int x=0;
    while(x<n)
    {
        while(last>0&&taken[vv[last]])last--;
        taken[vv[last]]=1;
        ans[pos[vv[last]]]=kk;
        x++;
        for(int i=pos[vv[last]]+1,j=0;j<k&&i<n;++i)
        {
            if(!taken[v[i]])
            {
               ans[i]=kk;
               taken[v[i]]=true;
               j++;
               x++;
            }
        }
        for(int i=pos[vv[last]]-1,j=0;i>-1&&j<k;--i){
            if(!taken[v[i]])
            {
                ans[i]=kk;
                taken[v[i]]=true;
                j++;
                x++;
            }
        }
        kk=3-kk;
    }
    for(auto&i:ans)cout<<i;

}

int main(){

    int tc=1;
    // cin>>tc;
    while (tc--)solve();

}


#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define vi vector<int>
#define vl vector<ll>
#define ii pair<ll, ll>
#define vii vector<ii>
#define PIii double PPPPPP = 3.14159265358979323846;
#define pb push_back
using namespace std;
const int N = 2e5 + 5;
bool taken[N];
int pos[N];
set<int> ss;
void run() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
void solve()
{
    int n,k;
    cin>>n>>k;
    vi v(n);
    for (int i = 0; i <n ; ++i) {
        cin>>v[i];
        pos[v[i]]=i;
        ss.insert(v[i]);
    }
    string ans(n,'.');
    int kk=1;
    while(sz(ss))
    {
        auto it=ss.end();
        for(;;)
        {
            --it;
            if(!taken[*it])
                break;
            if(it==ss.begin())
            {
                cout<<ans;
                return;
            }
        }
        int x=*it;
        ans[pos[x]]=kk+'0';
        taken[x]=1;
        for(int i=pos[x]+1,j=0;j<k&&i<n;i++)
        {
            if(!taken[v[i]]) {
                ans[i] = kk + '0', j++;
            }
                taken[v[i]]=1;
        }
        for(int i=pos[x]-1,j=0;j<k&&i>-1;i--)
        {
            if(!taken[v[i]]) {
                ans[i] = kk + '0', j++;
            }
            taken[v[i]]=1;
        }
        kk=kk==1? 2:1;
    }
    cout<<ans;

}

int main(){
    run();
    int tc=1;
    // cin>>tc;
    while (tc--)solve();

}


#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define vi vector<int>
#define vl vector<ll>
#define ii pair<ll, ll>
#define vii vector<ii>
#define PIii double PPPPPP = 3.14159265358979323846;
#define pb push_back
using namespace std;
const int N = 2e5 + 5;
bool taken[N];
int pos[N];
set<int> ss;
void run() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
void solve()
{
    int n,k;
    cin>>n>>k;
    vi v(n);
    for (int i = 0; i <n ; ++i) {
        cin>>v[i];
        pos[v[i]]=i;
        ss.insert(v[i]);
    }
    string ans(n,'.');
    int kk=1;
    while(sz(ss))
    {
        auto it=ss.end();
        it--;
        int x=*it;
        ans[pos[x]]=kk+'0';
        taken[x]=1;
        ss.erase(x);
        for(int i=pos[x]+1,j=0;j<k&&i<n;i++)
        {
            if(!taken[v[i]]) {
                ans[i] = kk + '0', j++;
                ss.erase(v[i]);
            }
                taken[v[i]]=1;
        }
        for(int i=pos[x]-1,j=0;j<k&&i>-1;i--)
        {
            if(!taken[v[i]]) {
                ans[i] = kk + '0', j++;
                ss.erase(v[i]);
            }
            taken[v[i]]=1;
        }
        kk=kk==1? 2:1;
    }
    cout<<ans;

}

int main(){
    run();
    int tc=1;
    // cin>>tc;
    while (tc--)solve();

}


#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define vi vector<int>
#define vl vector<ll>
#define ii pair<ll, ll>
#define vii vector<ii>
#define PIii double PPPPPP = 3.14159265358979323846;
#define pb push_back
using namespace std;
const int N = 2e5 + 5;
bool taken[N];
int vis[101];
int pos[N];
set<int> ss;
void solve()
{
    int n,k;
    cin>>n>>k;
    vi v(n);
    for (int i = 0; i <n ; ++i) {
        cin>>v[i];
        pos[v[i]]=i;
        ss.insert(v[i]);
    }
    string ans(n,'.');
    int kk=1;
    while(sz(ss))
    {
        auto it=ss.end();
        it--;
        int x=*it;
        ans[pos[x]]=kk+'0';
        taken[x]=1;
        ss.erase(x);
        for(int i=pos[x]+1,j=0;j<k&&i<n;i++)
        {
            if(!taken[v[i]]) {
                ans[i] = kk + '0', j++;
                ss.erase(v[i]);
            }
                taken[v[i]]=1;
        }
        for(int i=pos[x]-1,j=0;j<k&&i>-1;i--)
        {
            if(!taken[v[i]]) {
                ans[i] = kk + '0', j++;
                ss.erase(v[i]);
            }
            taken[v[i]]=1;
        }
        kk=kk==1? 2:1;
    }
    cout<<ans;

}

int main(){

    int tc=1;
    // cin>>tc;
    while (tc--)solve();

}


#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define vi vector<int>
#define vl vector<ll>
#define ii pair<ll, ll>
#define vii vector<ii>
#define PIii double PPPPPP = 3.14159265358979323846;
#define pb push_back
using namespace std;
const int N = 2e5 + 5;
bool taken[N];
int pos[N];
set<int> ss,index;
void solve()
{
    int n,k;
    cin>>n>>k;
    vi v(n),ans(n);
    for (int i = 0; i <n ; ++i) {
        cin>>v[i];
        pos[v[i]]=i;
        ss.insert(v[i]);
        index.insert(i);
    }
    int kk=1;
    while(ss.size()) {
        int top = *ss.rbegin();
        ans[pos[top]] = kk;
        index.erase(pos[top]);
        ss.erase(top);
        int rm = k;
        while (rm--) {
            auto it = index.lower_bound(pos[top]);
            if (it == index.begin())
                break;
            ans[*(--it)] = kk;
            ss.erase(v[*it]);
            index.erase(it);
        }
        rm = k;
        while (rm--) {
            auto it = index.upper_bound(pos[top]);
            if (it == index.end())
                break;
            ans[*it] = kk;
            ss.erase(v[*it]);
            index.erase(it);
        }
        kk=3-kk;
    }
    for(auto&i:ans)cout<<i;
}

int main(){

    int tc=1;
    // cin>>tc;
    while (tc--)solve();

}


#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define vi vector<int>
#define vl vector<ll>
#define ii pair<ll, ll>
#define vii vector<ii>
#define PIii double PPPPPP = 3.14159265358979323846;
#define pb push_back
using namespace std;
const int N = 2e5 + 5;
bool taken[N];
int pos[N];
set<int> ss;
void run() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
void solve()
{
    int n,k;
    cin>>n>>k;
    vi v(n);
    for (int i = 0; i <n ; ++i) {
        cin>>v[i];
        pos[v[i]]=i;
        ss.insert(v[i]);
    }
    string ans(n,'.');
    int kk=1;
    while(sz(ss))
    {
        auto it=ss.end();
        it--;
        while(taken[*it])it--;
        int x=*it;
        ans[pos[x]]=kk+'0';
        taken[x]=1;
        ss.erase(x);
        for(int i=pos[x]+1,j=0;j<k&&i<n;i++)
        {
            if(!taken[v[i]]) {
                ans[i] = kk + '0', j++;
            }
                taken[v[i]]=1;
        }
        for(int i=pos[x]-1,j=0;j<k&&i>-1;i--)
        {
            if(!taken[v[i]]) {
                ans[i] = kk + '0', j++;
            }
            taken[v[i]]=1;
        }
        kk=kk==1? 2:1;
    }
    cout<<ans;

}

int main(){
    run();
    int tc=1;
    // cin>>tc;
    while (tc--)solve();

}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], pos[N];
char ans[N];
bool vis[N];
inline int read()
{
    int sum = 0, f = 1;
    char c = getchar();
    while(c>'9'||c<'0') {if(c=='-') f = -f; c = getchar();}
    while(c>='0'&&c<='9') sum = sum*10 + c - 48, c = getchar();
    return sum*f;
}
set <int> s;
priority_queue <int> q;
int main()
{
	int n, k, cnt = 1, now;
	n = read(), k = read();
	for(int i=1;i<=n;i++)
	{
		a[i] = read();
		s.emplace(i);
		q.emplace(a[i]);
		pos[a[i]] = i;
	}
	while(!s.empty())
	{
		now = pos[q.top()];
		q.pop();
		if(vis[now]) continue;
		auto it = s.find(now);
		for(int i=0;i<=k&&it!=s.end();i++)
		{
			//cout << *it << endl;
			ans[*it] = cnt + 48;
			vis[*it] = 1;
			it = s.erase(it);
		}
		for(int i=1;i<=k&&it!=s.begin();i++)
		{
			it--;
			//cout << *it << endl;
			ans[*it] = cnt + 48;
			vis[*it] = 1;
			it = s.erase(it);
		}
		cnt = 3 - cnt;
	}
	puts(ans+1);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], pos[N];
char ans[N];
bool vis[N];
inline int read()
{
    int sum = 0, f = 1;
    char c = getchar();
    while(c>'9'||c<'0') {if(c=='-') f = -f; c = getchar();}
    while(c>='0'&&c<='9') sum = sum*10 + c - 48, c = getchar();
    return sum*f;
}
set <int> s;
priority_queue <int> q;
int main()
{
	int n, k, cnt = 1, now;
	n = read(), k = read();
	for(int i=1;i<=n;i++)
	{
		a[i] = read();
		s.emplace(i);
		q.emplace(a[i]);
		pos[a[i]] = i;
	}
	while(!s.empty())
	{
		cout << cnt << endl;
		now = pos[q.top()];
		q.pop();
		if(vis[now]) continue;
		auto it = s.find(now);
		for(int i=0;i<=k&&it!=s.end();i++)
		{
			//cout << *it << endl;
			ans[*it] = cnt + 48;
			vis[*it] = 1;
			it = s.erase(it);
		}
		for(int i=1;i<=k&&it!=s.begin();i++)
		{
			it--;
			//cout << *it << endl;
			ans[*it] = cnt + 48;
			vis[*it] = 1;
			it = s.erase(it);
		}
		cnt = 3 - cnt;
	}
	puts(ans+1);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
const int N = 2e5 + 5;
char s[N];
bool vis[N];
inline int read()
{
    int sum = 0, f = 1;
    char c = getchar();
    while(c>'9'||c<'0') {if(c=='-') f = -f; c = getchar();}
    while(c>='0'&&c<='9') sum = sum*10 + c - 48, c = getchar();
    return sum*f;
}
struct node
{
	int val, pos;
	bool operator < (const node& x) const
	{
		return val > x.val;
	}
};
node a[N];
int main()
{
	int n, k, cnt = -1, pos = 0;
	n = read(), k = read();
	for(int i=1;i<=n;i++)
	{
		a[i].val = read();
		a[i].pos = i;
	}
	sort(a+1,a+n+1);
	while(1)
	{
		cnt++;
		bool flag = false;
		while(pos<=n)
		{
			pos++;
			if(!vis[a[pos].pos])
			{
				flag = true;
				break;
			}
		}
		if(!flag) break;
		vis[a[pos].pos] = 1;
		s[a[pos].pos] = cnt%2 + 1 + '0';
		for(int i=a[pos].pos-1,tmp=0;i>=1&&tmp<k;i--)
		{
			if(!vis[i])
			{
				vis[i] = 1;
				s[i] = cnt%2 + 1 + '0';
				tmp++;
			}
			else i -= 2*k;
		}
		for(int i=a[pos].pos+1,tmp=0;i<=n&&tmp<k;i++)
		{
			if(!vis[i])
			{
				vis[i] = 1;
				s[i] = cnt%2 + 1 + '0';
				tmp++;
			}
			else i += 2*k;
		}
	}
	printf("%s\n",s+1);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
const int N = 2e5 + 5;
int a[N], pos[N];
char ans[N];
bool vis[N];
inline int read()
{
    int sum = 0, f = 1;
    char c = getchar();
    while(c>'9'||c<'0') {if(c=='-') f = -f; c = getchar();}
    while(c>='0'&&c<='9') sum = sum*10 + c - 48, c = getchar();
    return sum*f;
}
set <int> s;
priority_queue <int> q;
int main()
{
	int n, k, cnt = 2, now;
	n = read(), k = read();
	for(int i=1;i<=n;i++)
	{
		a[i] = read();
		s.emplace(i);
		q.emplace(a[i]);
		pos[a[i]] = i;
	}
	while(!s.empty())
	{
		cnt = 3 - cnt;
		now = pos[q.top()];
		q.pop();
		if(vis[now]) continue;
		auto it = s.find(now);
		for(int i=0;i<=k&&it!=s.end();i++)
		{
			ans[*it] = cnt + '0';
			vis[*it] = 1;
			it = s.erase(it);
		}
		for(int i=1;i<=k&&it!=s.begin();i++)
		{
			it--;
			ans[*it] = cnt + '0';
			vis[*it] = 1;
			it = s.erase(it);
		}
	}
	printf("%s\n",ans+1);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
const int N = 2e5 + 5;
char s[N];
bool vis[N];
inline int read()
{
    int sum = 0, f = 1;
    char c = getchar();
    while(c>'9'||c<'0') {if(c=='-') f = -f; c = getchar();}
    while(c>='0'&&c<='9') sum = sum*10 + c - 48, c = getchar();
    return sum*f;
}
struct node
{
	int val, pos;
};
node tmp[N];
int a[N], n;
void sort()
{
	int id = 0;
	for(int i=1;i<=n;i++) a[n-tmp[i].val+1] = tmp[i].pos;
}
int main()
{
	int k, cnt = -1, now = 0;
	n = read(), k = read();
	for(int i=1;i<=n;i++)
	{
		tmp[i].val = read();
		tmp[i].pos = i;
	}
	sort();
	while(1)
	{
		cnt++;
		bool flag = false;
		while(now<=n)
		{
			now++;
			if(!vis[a[now]])
			{
				flag = true;
				break;
			}
		}
		if(!flag) break;
		vis[a[now]] = 1;
		s[a[now]] = cnt%2 + 1 + '0';
		for(int i=a[now]-1,tmp=0;i>=1&&tmp<k;i--)
		{
			if(!vis[i])
			{
				vis[i] = 1;
				s[i] = cnt%2 + 1 + '0';
				tmp++;
			}
			else i -= 2*k;
		}
		for(int i=a[now]+1,tmp=0;i<=n&&tmp<k;i++)
		{
			if(!vis[i])
			{
				vis[i] = 1;
				s[i] = cnt%2 + 1 + '0';
				tmp++;
			}
			else i += 2*k;
		}
	}
	printf("%s\n",s+1);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], pos[N];
char ans[N];
bool vis[N];
inline int read()
{
    int sum = 0, f = 1;
    char c = getchar();
    while(c>'9'||c<'0') {if(c=='-') f = -f; c = getchar();}
    while(c>='0'&&c<='9') sum = sum*10 + c - 48, c = getchar();
    return sum*f;
}
set <int> s;
priority_queue <int> q;
int main()
{
	int n, k, cnt = 2, now;
	n = read(), k = read();
	for(int i=1;i<=n;i++)
	{
		a[i] = read();
		s.emplace(i);
		q.emplace(a[i]);
		pos[a[i]] = i;
	}
	while(!s.empty())
	{
		cout << cnt << endl;
		now = pos[q.top()];
		q.pop();
		if(vis[now]) continue;
		auto it = s.find(now);
		for(int i=0;i<=k&&it!=s.end();i++)
		{
			//cout << *it << endl;
			ans[*it] = cnt + 48;
			vis[*it] = 1;
			it = s.erase(it);
		}
		for(int i=1;i<=k&&it!=s.begin();i++)
		{
			it--;
			//cout << *it << endl;
			ans[*it] = cnt + 48;
			vis[*it] = 1;
			it = s.erase(it);
		}
		cnt = 3 - cnt;
	}
	puts(ans+1);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define ll int
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
int main()
{
    boost;
    ll n,i,x,k,y,j;
    cin>>n>>k;
    ll ind[n],b[n],ans[n];
    vector<ll>a;
    for(i=0;i<n;i++){
        cin>>b[i];
        a.pb(b[i]);
        ind[b[i]]=i;
    }
    sort(b,b+n);
    vector<bool>done(n,0);
    x=0;
    for(i=n-1;i>=0;i--){
        if(a.empty()) break;
        if(done[b[i]]==1) continue;
        y=find(a.begin(),a.end(),b[i])-a.begin();
        ll s,e,c=0,d=a.size();
        d--;
        s=max(c,y-k);
        e=min(d,y+k)+1;
        for(j=s;j<e;j++) {
            ans[ind[a[j]]]=x;
            done[a[j]]=1;
        }
        a.erase(a.begin()+s,a.begin()+e);
        x=1-x;
    }
    for(i=0;i<n;i++) cout<<ans[i]+1;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define ll int
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
const int N=2e5+10;
ll ind[N],b[N],ans[N];
vector<ll>a;
int main()
{
    boost;
    ll n,i,x,k,y,j;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>b[i];
        a.pb(b[i]);
        ind[b[i]]=i;
    }
    sort(b,b+n);
    x=1;
    for(i=n-1;i>=0;i--){
        if(ans[ind[b[i]]]) continue;
        y=find(a.begin(),a.end(),b[i])-a.begin();
        ll s,e,c=0,d=a.size()-1;
        s=max(c,y-k);
        e=min(d,y+k);
        for(j=s;j<=e;j++) ans[ind[a[j]]]=x;
        a.erase(a.begin()+s,a.begin()+e+1);
        if(x==1) x=2;
        else x=1;
    }
    for(i=0;i<n;i++) cout<<ans[i];
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
int main()
{
    boost;
    ll n,i,x,k,y,j;
    cin>>n>>k;
    ll ind[n],b[n],ans[n];
    vector<ll>a;
    for(i=0;i<n;i++){
        cin>>b[i];
        a.pb(b[i]);
        ind[b[i]]=i;
    }
    sort(b,b+n);
    vector<bool>done(n,0);
    x=0;
    for(i=n-1;i>=0;i--){
        if(a.empty()) break;
        if(done[b[i]]==1) continue;
        y=find(a.begin(),a.end(),b[i])-a.begin();
        ll s,e,c=0,d=a.size();
        d--;
        s=max(c,y-k);
        e=min(d,y+k)+1;
        for(j=s;j<e;j++) {
            ans[ind[a[j]]]=x;
            done[a[j]]=1;
        }
        a.erase(a.begin()+s,a.begin()+e);
        x=1-x;
    }
    for(i=0;i<n;i++) cout<<ans[i]+1;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
const int N=2e6+5;
ll ind[N],b[N],ans[N];
vector<ll>a;
vector<bool>done(N,0);
int main()
{
    boost;
    ll n,i,x,k,y,j;
    scanf("%lld%lld",&n,&k);
    for(i=0;i<n;i++){
        scanf("%lld",&b[i]);
        a.pb(b[i]);
        ind[b[i]]=i;
    }
    sort(b,b+n);
    x=0;
    for(i=n-1;i>=0;i--){
        if(done[b[i]]==1) continue;
        y=find(a.begin(),a.end(),b[i])-a.begin();
        ll s,e,c=0,d=a.size()-1;
        s=max(c,y-k);
        e=min(d,y+k);
        for(j=s;j<=e;j++) {
            ans[ind[a[j]]]=x;
            done[a[j]]=1;
        }
        a.erase(a.begin()+s,a.begin()+e+1);
        x=1-x;
    }
    for(i=0;i<n;i++) printf("%lld",ans[i]+1);
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
int main()
{
    boost;
    ll n,i,x,k,y,j;
    scanf("%lld%lld",&n,&k);
    ll ind[n],b[n],ans[n];
    vector<ll>a;
    for(i=0;i<n;i++){
        scanf("%lld",&b[i]);
        a.pb(b[i]);
        ind[b[i]]=i;
    }
    sort(b,b+n);
    vector<bool>done(n,0);
    x=0;
    for(i=n-1;i>=0;i--){
        if(done[b[i]]==1) continue;
        y=find(a.begin(),a.end(),b[i])-a.begin();
        ll s,e,c=0,d=a.size();
        d--;
        s=max(c,y-k);
        e=min(d,y+k)+1;
        for(j=s;j<e;j++) {
            ans[ind[a[j]]]=x;
            done[a[j]]=1;
        }
        a.erase(a.begin()+s,a.begin()+e);
        x=1-x;
    }
    for(i=0;i<n;i++) printf("%lld",ans[i]+1);
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
const int N=2e5+10;
ll ind[N],b[N],ans[N];
vector<ll>a;
int main()
{
    boost;
    ll n,i,x,k,y,j;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>b[i];
        a.pb(b[i]);
        ind[b[i]]=i;
    }
    sort(b,b+n);
    x=1;
    for(i=n-1;i>=0;i--){
        if(ans[ind[b[i]]]) continue;
        y=find(a.begin(),a.end(),b[i])-a.begin();
        ll s,e,c=0,d=a.size()-1;
        s=max(c,y-k);
        e=min(d,y+k);
        for(j=s;j<=e;j++) ans[ind[a[j]]]=x;
        a.erase(a.begin()+s,a.begin()+e+1);
        if(x==1) x=2;
        else x=1;
    }
    for(i=0;i<n;i++) cout<<ans[i];
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
int main()
{
    boost;
    ll n,i,x,k,y,j;
    scanf("%lld%lld",&n,&k);
    ll ind[n],b[n],ans[n];
    vector<ll>a;
    for(i=0;i<n;i++){
        scanf("%lld",&b[i]);
        a.pb(b[i]);
        ind[b[i]]=i;
    }
    sort(b,b+n);
    vector<bool>done(n,0);
    x=0;
    for(i=n-1;i>=0;i--){
        if(a.empty()) break;
        if(done[b[i]]==1) continue;
        y=find(a.begin(),a.end(),b[i])-a.begin();
        ll s,e,c=0,d=a.size();
        d--;
        s=max(c,y-k);
        e=min(d,y+k)+1;
        for(j=s;j<e;j++) {
            ans[ind[a[j]]]=x;
            done[a[j]]=1;
        }
        a.erase(a.begin()+s,a.begin()+e);
        x=1-x;
    }
    for(i=0;i<n;i++) printf("%lld",ans[i]+1);
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9+8
#define OO 1e18
#define EPS 1e-9
#define Endl '\n'
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=2e5+5;
int n,k;
int a[maxn];
int out[maxn];
bool vis[maxn];
int mkan[maxn];
int main()
{
    scanf("%d%d",&n,&k);
    priority_queue<pair<int,int> >pq;
    for(int i=0;i<n;++i){
        scanf("%d",a+i);
        pq.push({a[i],i});
    }
    bool fen=1;
    while(pq.size()){
        int val=pq.top().f;
        int idx=pq.top().s;
        pq.pop();
        if(vis[idx])continue;
        fen=!fen;
        vis[idx]=true;
        out[idx]=fen+1;
        for(int i=idx+1,j=0;i<n&&j<k;++i,++j){
            if(vis[i])i=mkan[i]-1;
            vis[i]=true;
            out[i]=fen+1;
        }
        for(int i=idx-1,j=0;i>=0&&j<k;--i,++j){
            if(vis[i])i=mkan[i]-1;
            vis[i]=true;
            out[i]=fen+1;
        }
        mkan[max(0,idx-k)]=min(n-1,idx+k);
        mkan[min(n-1,idx+k)]=max(0,idx-k);
    }
    for(int i=0;i<n;++i)printf("%d",out[i]);
    re 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9+8
#define OO 1e18
#define EPS 1e-9
#define Endl '\n'
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=2e5+5;
int n,k;
int a[maxn];
int out[maxn];
bool vis[maxn];
int mkan[maxn];
int main()
{
    scanf("%d%d",&n,&k);
    priority_queue<pair<int,int> >pq;
    for(int i=0;i<n;++i){
        scanf("%d",a+i);
        pq.push({a[i],i});
    }
    bool fen=1;
    while(pq.size()){
        int val=pq.top().f;
        int idx=pq.top().s;
        pq.pop();
        if(vis[idx])continue;
        fen=!fen;
        vis[idx]=true;
        out[idx]=fen+1;
        for(int i=idx+1,j=0;i<n&&j<k;++i,++j){
            if(vis[i])i=mkan[i]-1;
            vis[i]=true;
            out[i]=fen+1;
        }
        for(int i=idx-1,j=0;i>=0&&j<k;--i,++j){
            if(vis[i])i=mkan[i]+1;
            vis[i]=true;
            out[i]=fen+1;
        }
        mkan[max(0,idx-k)]=min(n-1,idx+k);
        mkan[min(n-1,idx+k)]=max(0,idx-k);
    }
    for(int i=0;i<n;++i)printf("%d",out[i]);
    re 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9+8
#define OO 1e18
#define EPS 1e-9
#define Endl '\n'
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=2e5+5;
int n,k;
bool vis[maxn];
int a[maxn],out[maxn];
int prv[maxn],nxt[maxn];
int main()
{
    scanf("%d%d",&n,&k);
    priority_queue<pair<int,int> >pq;
    for(int i=1;i<=n;++i){
        scanf("%d",a+i);
        pq.push({a[i],i});
        prv[i]=i-1;
        nxt[i]=i+1;
    }
    bool fen=1;
    while(pq.size()){
        int val=pq.top().f;
        int idx=pq.top().s;
        pq.pop();
        if(vis[idx])continue;
        fen=!fen;
        vis[idx]=true;
        out[idx]=fen+1;
        int len=k,awl=nxt[idx],tani=prv[idx];
        while(len--&&awl<=n){
            vis[awl]=true;
            out[awl]=fen+1;
            awl=nxt[awl];
        }
        len=k;
        while(len--&&tani>0){
            vis[tani]=true;
            out[tani]=fen+1;
            tani=prv[tani];
        }
        nxt[tani]=awl;
        prv[awl]=tani;
    }
    for(int i=1;i<=n;++i)printf("%d",out[i]);
    re 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9+8
#define OO 1e18
#define EPS 1e-9
#define Endl '\n'
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=2e5+5;
int n,k;
int a[maxn];
int out[maxn];
bool vis[maxn];
int mkan[maxn];
int main()
{
    scanf("%d%d",&n,&k);
    priority_queue<pair<int,int> >pq;
    for(int i=0;i<n;++i){
        scanf("%d",a+i);
        pq.push({a[i],i});
    }
    bool fen=1;
    while(pq.size()){
        int val=pq.top().f;
        int idx=pq.top().s;
        pq.pop();
        if(vis[idx])continue;
        fen=!fen;
        vis[idx]=true;
        out[idx]=fen+1;
        for(int i=idx+1,j=0;i<n&&j<k;++i,++j){
            if(vis[i])i=mkan[i]+1;
            vis[i]=true;
            out[i]=fen+1;
        }
        for(int i=idx-1,j=0;i>=0&&j<k;--i,++j){
            if(vis[i])i=mkan[i]-1;
            vis[i]=true;
            out[i]=fen+1;
        }
        mkan[max(0,idx-k)]=min(n-1,idx+k);
        mkan[min(n-1,idx+k)]=max(0,idx-k);
    }
    for(int i=0;i<n;++i)printf("%d",out[i]);
    re 0;
}