[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≤𝑘≤𝑛≤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 𝑛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
Examples
Input
5 2
2 4 5 3 1
Output
11111
正确解法:
用链表。但是链表不会QAQ
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 }