微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

[CF]Codeforces Round #552 (Div. 3)(坑)

E. Two Teams

Description

There are ??n 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 ??i-th student has integer programming skill ????ai. All programming skills are distinct and between 11 and ??n,inclusive.

Firstly,the first coach will choose the student with maximum programming skill among all students not taken into any team, and ??k closest students to the left of him and ??k closest students to the right of him (if there are less than ??k 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 ??n and ??k (1????21051≤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 ??n integers ??1,??2,,????a1,a2,…,an (1??????1≤ai≤n),where ????ai is the programming skill of the ??i-th student. It is guaranteed that all programming skills are distinct。

output

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

Examples

Input

5 2
2 4 5 3 1

Output

11111

正确解法:

用链表。但是链表不会QAQ

分享图片

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string>
 4 #include<cstring>
 5 #include<map>
 6 #include<set>
 7 #include<vector>
 8 #include<queue>
 9 #include<algorithm>
10 #include<cmath>
11 #include<list>
12 using namespace std;
13 typedef long long ll;
14 const int inf=0x7fffffff;
15 const int N=100000+100;
16 const int M=9999999;
17 const ll mod=1000000000+7;
18 int t,n,m,k,p,l,r,u,v;
19 int ans[N],cnt,flag,temp,sum;
20 int a[N];
21 char str;
22 struct node{
23     int val,id;
24     bool operator <(const node &S)const{
25         return val<S.val;
26     }
27 }e[N];
28 list<node>st;
29 list<node>::iterator it[N];
30 int main()
31 {
32     scanf("%d %d",&n,&k);
33     for(int i=1;i<=n;i++){
34         scanf("%d",&e[i].val);
35         e[i].id=i;
36         st.push_back(e[i]);
37         it[i]=--st.end();
38     }
39     sort(e+1,e+n+1);
40     int pos=1;
41     for(int i=n;i>=1;i--){
42         if(!ans[e[i].id]){
43             int Now=e[i].id;
44             ans[Now]=pos;
45             list<node>::iterator l=it[Now],r=it[Now];
46             for(int j=1;j<=k;j++){
47                 if(l!=st.begin())--l;
48                 if(r!=--st.end())++r;
49             }
50             ++r;
51             while(l!=r) {
52                 ans[l->id]=pos;
53                 l=st.erase(l);
54             }
55             pos=3-pos;
56         }
57 
58     }
59     for(int i=1;i<=n;i++)
60         cout<<ans[i];
61     cout<<endl;
62     return 0;
63 }
View Code

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。