Codeforces E. Two Teams

版权声明:转载请标明出处 https://blog.csdn.net/weixin_41190227/article/details/89460240

E. Two Teams

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Copy

5 2
2 4 5 3 1

output

Copy

11111

input

Copy

5 1
2 1 3 5 4

output

Copy

22111

input

Copy

7 1
7 2 1 3 5 4 6

output

Copy

1121122

input

Copy

5 1
2 4 5 3 1

output

Copy

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).

题目大意:一些学生有能力值,有两个教练选人,规则如下,每次都会选一个能力值最大的人,然后再选择他左右两边的k个人。两个教练一次选择,最后让你输出每个人是被第几个教练选走的。

解题思路: 对每个人的位置和能力值进行保存,按照能力值由高到低的顺序进行排序,用一个队列保存能力从高到低的学生的编号,用一个set保存整个数组的位置,每次都从队列中取出最大的那个一个人的位置,在set里面查找,再向左右两边分别进行k次的遍历,遍历的人的位置都保存在一个vector里,最后遍历这个vector进行标记是第几个教练选得人,再在set中进行删除就好了。按照这样这样模拟下去直到set为空就解决了。

题目链接:https://codeforces.com/contest/1154/problem/E

/*
@Author: Top_Spirit
@Language: C++
*/
#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair < int, int > P ;
const int Maxn = 2e5 + 10 ;

int n, k ;

int main (){
    cin >> n >> k ;
    vector < P > a(n) ;
    for (int i = 0; i < n; i++){
        cin >> a[i].first ;
        a[i].second = i ;
    }
    sort(a.rbegin(), a.rend()) ;
    queue < int > que ;
    for (int i = 0; i < n; i++) que.push(a[i].second) ;
    set < int > se ;
    for (int i = 0; i < n; i++) se.insert(i) ;
    string ans(n, '0') ;
    int cnt = 0 ;
    while (!se.empty()){
        while (!se.count(que.front())) que.pop() ;
        int index = que.front() ;
        que.pop() ;
        vector < int > add ;
        auto it = se.find(index) ;
        for (int i = 0; i <= k; i++){
            add.push_back(*it) ;
            if (it == se.begin()) break ;
            it-- ;
        }
        it = next(se.find(index)) ;
        for (int i = 0; i < k; i++){
            if (it == se.end()) break ;
            add.push_back(*it) ;
            it++ ;
        }
        for (auto i : add){
            ans[i] = '1' + cnt ;
            se.erase(i) ;
        }
        cnt ^= 1 ;
    }
    cout << ans << endl ;
    return 0 ;
}

猜你喜欢

转载自blog.csdn.net/weixin_41190227/article/details/89460240