Codeforces Round #552 (Div. 3) E

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=2e5+5;
list<pair<int, int>>l;
list<pair<int, int>>::iterator ite[maxn];
pair<int, int>a[maxn];
bool vis[maxn];
int ans[maxn];
int n, k,team;
int main()
{
	cin>>n>>k;
	team = 1;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
		l.push_back(a[i]);
		ite[i] = --l.end();
	}
	sort(a + 1, a + 1 + n);
	for (int i = n; i >= 1; i--)
	{
		int t = a[i].second;
		if (vis[t])continue;
		list<pair<int, int>>::iterator l1 = ite[t], r1 = ite[t];
		for(int j=1;j<=k;j++)
		{
			if (l1 != l.begin())l1--;
			if (r1 != --l.end())r1++;
		}
		r1++;
		while (l1 != r1)
		{
			ans[l1->second] = team;
			vis[l1->second] = 1;
			l1=l.erase(l1);
		}
		team = 3 - team;
	}
	for (int i = 1; i <= n; i++)
		cout << ans[i];cout<<endl;
}

猜你喜欢

转载自blog.csdn.net/wzazzy/article/details/89679543
今日推荐