cf 552 (Div. 3)Two Teams

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 1  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≤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,…,an  (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.
5 2
2 4 5 3 1
11111
7 1
7 2 1 3 5 4 6
1121122
定个目标,用stl容器写出让自己汗颜的最最优美代码。

#include <stdio.h>
#include <bits/stdc++.h>
#define fst first
#define sed second
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
bool one[N]; //是否1队
int main(){
	map<int, int> pos, val; //位置顺序 值顺序
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i){
		int v;
		scanf("%d", &v);
		pos[i] = v;
		val[v] = i;
	}
	int flag = 1;
	while (!val.empty()){
		int p = val.rbegin()->second; //最大值位置
		for (int i = 0; i < k; ++i) //左侧
		{
			auto it = pos.lower_bound(p);
			if (it == pos.begin())
				break;
			--it;
			if (flag) one[it->first] = 1;
			val.erase(it->second);
			pos.erase(it);
		}
		for (int i = 0; i < k; ++i) //右侧
		{
			auto it = pos.upper_bound(p);
			if (it == pos.end())
				break;
			if (flag) one[it->first] = 1;
			val.erase(it->second);
			pos.erase(it);
		}
		if (flag) one[p] = 1;
		val.erase(pos[p]);
		pos.erase(p);
		flag ^= 1;
	}
	for (int i = 1; i <= n; ++i)
		putchar(one[i] ? '1' : '2');
	cout << endl;
	return 0;
}

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值