E. Two Teams

E. Two Teams

time limit per test

2 seconds

memory limit per test

256 megabytes


There are nn students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.

The ii-th student has integer programming skill aiai. All programming skills are distinct and between 11 and nn, inclusive.

Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and kk closest students to the left of him and kk closest students to the right of him (if there are less than kk students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).

Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.

Input

The first line of the input contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105) — the number of students and the value determining the range of chosen students during each move, respectively.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n), where aiai is the programming skill of the ii-th student. It is guaranteed that all programming skills are distinct.

Output

Print a string of nn characters; ii-th character should be 1 if ii-th student joins the first team, or 2 otherwise.

Examples

input

5 2
2 4 5 3 1

output

11111

input

5 1
2 1 3 5 4

output

22111

input

7 1
7 2 1 3 5 4 6

output

1121122

input

5 1
2 4 5 3 1

output

21112

Note

In the first example the first coach chooses the student on a position 33, and the row becomes empty (all students join the first team).

In the second example the first coach chooses the student on position 44, and the row becomes [2,1][2,1] (students with programming skills [3,4,5][3,4,5] join the first team). Then the second coach chooses the student on position 11, and the row becomes empty (and students with programming skills [1,2][1,2] join the second team).

In the third example the first coach chooses the student on position 11, and the row becomes [1,3,5,4,6][1,3,5,4,6] (students with programming skills [2,7][2,7] join the first team). Then the second coach chooses the student on position 55, and the row becomes [1,3,5][1,3,5] (students with programming skills [4,6][4,6] join the second team). Then the first coach chooses the student on position 33, and the row becomes [1][1] (students with programming skills [3,5][3,5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 11 joins the second team).

In the fourth example the first coach chooses the student on position 33, and the row becomes [2,1][2,1] (students with programming skills [3,4,5][3,4,5] join the first team). Then the second coach chooses the student on position 11, and the row becomes empty (and students with programming skills [1,2][1,2] join the second team).

 

用鏈表

題意:輪到一個教練選人的時候,先定位到當前剩餘人中 programming skills 的值最大的那個,再加上其左右兩邊k個人。

 

AC代碼:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <map>
#include <set>
#include <cassert> 
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
const ll mod = 1e9 + 7;
const int N = 1e6;

ll n, m, k;
int ans[200006];
struct node {
	int id;
	int a;
};
bool cmp(const node a, const node b) {
	return a.a < b.a;
}
vector<node> v;
int Next[200006];
int pre[200006];
int main() {
	cin >> n >> k;
	int key;
	memset(ans, -1, sizeof(ans));
	for (int i = 1; i <= n; i++) {
		cin >> key;
		v.pb(node{ i, key });
	}
	sort(v.begin(), v.end(), cmp);
	Next[0] = 1;
	for (int i = 1; i<n; i++) {
		pre[i] = i - 1;
		Next[i] = i + 1;
	}
	pre[n] = n - 1;
	Next[n] = 0;
	int flag = 1;
	while (1) {
		if (!Next[0]) break;

		int Max = 0, Maxi = 0;
		for (int i = v.size() - 1; i >= 0; i--) {
			if (ans[v[i].id] == -1) {
				Maxi = v[i].id;
				v.pop_back();
				break;
			}
			else 
				v.pop_back();
		}
		int tot = 0;
		for (int i = Next[Maxi]; i != 0 && tot<k; i = Next[i]) {
			ans[i] = flag;
			Next[Maxi] = Next[i];
			pre[Next[i]] = Maxi;
			tot++;
		}
		tot = 0;
		for (int i = pre[Maxi]; i != 0 && tot<k; i = pre[i]) {
			ans[i] = flag;
			pre[Maxi] = pre[i];
			Next[pre[i]] = Maxi;
			tot++;
		}
		ans[Maxi] = flag;
		Next[pre[Maxi]] = Next[Maxi];
		pre[Next[Maxi]] = pre[Maxi];
		/*for (int i = Next[0]; i != 0; i = Next[i]) {
			cout << i<<' ';
		}
		cout << '\n';
		for (int i = 1; i <= n; i++) {
			cout << ans[i] << ' ';
		}
		cout << '\n';*/
		flag ^= 1;
	}

	for (int i = 1; i <= n; i++) {
		if (ans[i]) cout << 1;
		else cout << 2;
	}
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章