[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

相关文章

Css3如何实现鼠标移上变长特效?(图文+视频)
css3怎么实现鼠标悬停图片时缓慢变大效果?(图文+视频)
jquery如何实现点击网页回到顶部效果?(图文+视频)
css3边框阴影效果怎么做?(图文+视频)
css怎么实现圆角边框和圆形效果?(图文+视频教程)
Css3如何实现旋转移动动画特效