#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<set>
using namespace std;
const int maxn = 2e5 + 10;
int n, k;
int main()
{
cin >> n >> k;
vector<pair<int, int> > a(n);
for(int i = 0; i < n; i++)
{
cin >> a[i].first;
a[i].second = i;
}
sort(a.rbegin(), a.rend());
//for(int i = 0; i < n; i++)
//cout << a[i].first << " " << a[i].second << endl;
queue<int> q;
for(int i = 0; i < n; i++)
q.push(a[i].second);
set<int> idx;
for(int i = 0; i < n; i++)
{
idx.insert(i);
}
string ans(n, '0');
int who = 0;
while(!idx.empty())
{
while(!idx.count(q.front())) //已经被选走,往后走
{
q.pop();
}
int pos = q.front(); //
q.pop();
vector<int> add;
set<int>::iterator it = idx.find(pos);
for(int i = 0; i <= k; i++)
{
add.push_back(*it);
if(it == idx.begin()) break;
--it;
}
it = idx.find(pos);
it++;
for(int i = 0; i < k; i++)
{
if(it == idx.end()) break;
add.push_back(*it);
++it;
}
for(int i = 0; i < add.size(); i++)
{
int t = add[i];
idx.erase(t);
ans[t] = '1' + who;
}
who ^= 1;
//cout << "now who is " << who << endl;
}
cout << ans << endl;
return 0;
}
cf Round552E(思维)
猜你喜欢
转载自blog.csdn.net/qq_38577732/article/details/89683957
今日推荐
周排行