ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforces Round #552 (Div. 3)E. Two Teams【STL模拟】

2019-04-19 17:53:44  阅读:382  来源: 互联网

标签:coach STL Codeforces Two students second student team first


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

 

 

分析:直接开两个set,一个维护权值,另一个维护id。然后模拟就可以了。

我写的大常数写法,用的vector。

#include "bits/stdc++.h"
using namespace std;
int a[200004];
int b[200004];
int ans[200004];
int main()
{
    int n,k;cin>>n>>k;
    set<int>s;
    vector<int>v;
    for (int i = 1; i <= n; ++i) {
        scanf("%d",&a[i]);
        b[a[i]]=i;
        s.insert(a[i]);
        v.push_back(i);
    }
    int cnt=0;
    while(!v.empty())
    {
        int x=*(--s.end());
        s.erase(--s.end());
        int id=b[x];
        ans[id]=cnt+1;
        int pos=lower_bound(v.begin(),v.end(),id)-v.begin();
        int c=k;
        while(c--)
        {
            if(pos+1==v.size())break;
            s.erase(a[v[pos+1]]);
            ans[v[pos+1]]=cnt+1;
            v.erase(v.begin()+pos+1);
        }
        c=k;
        while(c--)
        {
            if(pos==0)break;
            s.erase(a[v[pos-1]]);
            ans[v[pos-1]]=cnt+1;
            v.erase(v.begin()+pos-1);
            pos--;
        }
        v.erase(v.begin()+pos);
        cnt^=1;
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d",ans[i]);
    }
}

 

标签:coach,STL,Codeforces,Two,students,second,student,team,first
来源: https://blog.csdn.net/qq_42671946/article/details/89405084

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有