https://www.luogu.com.cn/problem/CF1154E
const int N = 200000 + 50;
int ans[N];
int b[N];
struct node
{
int zhi, zuo, you;
}a[N];
set<int> s;
void solve()
{
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
cin >> a[i].zhi;
a[i].zuo = i - 1;
a[i].you = i + 1;
b[a[i].zhi] = i;
s.insert(a[i].zhi);
}
int nn = n;
int now = 1;
while (nn)
{
int x = *(--s.end());
ans[b[x]] = now;
for (int i = a[b[x]].zuo, j = 1; i >= 1 && j<= k; j++, i = a[i].zuo)
{
nn--;
ans[i] = now;
s.erase(a[i].zhi);
a[a[i].you].zuo = a[i].zuo;
a[a[i].zuo].you = a[i].you;
}
for (int i = a[b[x]].you, j = 1; i <= n && j <= k; i = a[i].you, j++)
{
nn--;
ans[i] = now;
s.erase(a[i].zhi);
a[a[i].you].zuo = a[i].zuo;
a[a[i].zuo].you = a[i].you;
}
nn--;
s.erase(x);
a[a[b[x]].you].zuo = a[b[x]].zuo;
a[a[b[x]].zuo].you = a[b[x]].you;
now = now % 2 + 1;
}
for (int i = 1; i <= n; i++)
{
cout << ans[i] ;
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
}