http://codeforces.com/problemset/problem/1154/E

E. Two Teams
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 n

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.

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 3

, and the row becomes empty (all students join the first team).

In the second example the first coach chooses the student on position 4

, and the row becomes [2,1] (students with programming skills [3,4,5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1,2]

join the second team).

In the third example the first coach chooses the student on position 1

, and the row becomes [1,3,5,4,6] (students with programming skills [2,7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1,3,5] (students with programming skills [4,6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3,5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1

joins the second team).

In the fourth example the first coach chooses the student on position 3

, and the row becomes [2,1] (students with programming skills [3,4,5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1,2] join the second team).

题意:给你n个数排成一排,两个教练轮流在队伍中找到最大的那个数,

并将该数两边k个同时提出队伍,然后第二教练重复上述步骤,直到队伍没人结束。

问每个数被哪一个教练选中。

#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 1000000007
#define PI acos(-1)
using namespace std;
typedef long long ll ; int main()
{
int n , k ;
scanf("%d%d" , &n , &k);
vector<pair<int , int> >v(n);//给定容量的vector
for(int i = ; i < n ; i++)
{
scanf("%d" , &v[i].first);
v[i].second = i ;
}
sort(v.rbegin() , v.rend());//反相迭代降序,正向就为升序
queue<int>q;
for(int i = ; i < n ; i++)
{
q.push(v[i].second);
}
set<int>s;
for(int i = ; i < n ; i++)
{
s.insert(i);
}
int who = ;
string ans(n , '');//赋值为n个0字符
while(!s.empty())
{
while(!s.count(q.front()))
{
q.pop();
}
int pos = q.front();
vector<int>v1;
auto it = s.find(pos);
for(int i = ; i <= k ; i++)
{
v1.push_back(*it);
it++ ;
if(it == s.end())
break ;
}
it = prev(s.find(pos));//迭代器的前一个
// it = next(s.find(pos)) 迭代器的后一个
for(int i = ; i < k ; i++)
{
v1.push_back(*it);
if(it == s.begin())
break ;
it-- ;
}
for(auto it : v1)
{
s.erase(it);
ans[it] = ''+ who;
}
who ^= ;
}
cout << ans << endl; return ;
}

stl应用的更多相关文章

  1. 详细解说 STL 排序(Sort)

    0 前言: STL,为什么你必须掌握 对于程序员来说,数据结构是必修的一门课.从查找到排序,从链表到二叉树,几乎所有的算法和原理都需要理解,理解不了也要死记硬背下来.幸运的是这些理论都已经比较成熟,算 ...

  2. STL标准模板库(简介)

    标准模板库(STL,Standard Template Library)是C++标准库的重要组成部分,包含了诸多在计算机科学领域里所常见的基本数据结构和基本算法,为广大C++程序员提供了一个可扩展的应 ...

  3. STL的std::find和std::find_if

    std::find是用来查找容器元素算法,但是它只能查找容器元素为基本数据类型,如果想要查找类类型,应该使用find_if. 小例子: #include "stdafx.h" #i ...

  4. STL: unordered_map 自定义键值使用

    使用Windows下 RECT 类型做unordered_map 键值 1. Hash 函数 计算自定义类型的hash值. struct hash_RECT { size_t operator()(c ...

  5. C++ STL简述

    前言 最近要找工作,免不得要有一番笔试,今年好像突然就都流行在线笔试了,真是搞的我一塌糊涂.有的公司呢,不支持Python,Java我也不会,C有些数据结构又有些复杂,所以是时候把STL再看一遍了-不 ...

  6. codevs 1285 二叉查找树STL基本用法

    C++STL库的set就是一个二叉查找树,并且支持结构体. 在写结构体式的二叉查找树时,需要在结构体里面定义操作符 < ,因为需要比较. set经常会用到迭代器,这里说明一下迭代器:可以类似的把 ...

  7. STL bind1st bind2nd详解

    STL bind1st bind2nd详解   先不要被吓到,其实这两个配接器很简单.首先,他们都在头文件<functional>中定义.其次,bind就是绑定的意思,而1st就代表fir ...

  8. STL sort 函数实现详解

    作者:fengcc 原创作品 转载请注明出处 前几天阿里电话一面,被问到STL中sort函数的实现.以前没有仔细探究过,听人说是快速排序,于是回答说用快速排序实现的,但听电话另一端面试官的声音,感觉不 ...

  9. STL的使用

    Vector:不定长数组 Vector是C++里的不定长数组,相比传统数组vector主要更灵活,便于节省空间,邻接表的实现等.而且它在STL中时间效率也很高效:几乎与数组不相上下. #include ...

  10. [C/C++] C/C++延伸学习系列之STL及Boost库概述

    想要彻底搞懂C++是很难的,或许是不太现实的.但是不积硅步,无以至千里,所以抽时间来坚持学习一点,总结一点,多多锻炼几次,相信总有一天我们会变得"了解"C++. 1. C++标准库 ...

随机推荐

  1. js中或者vue中 Object.assign()用法详解

    Object.assign()是浅拷贝. 合并对象 var o1 = { a: 1 }; var o2 = { b: 2 }; var o3 = { c: 3 }; var obj = Object. ...

  2. CentOS 系统free命令

    CentOS 6 下free命令 各参数含义:total:总物理内存used:已使用内存free:完全未被使用的内存shared:应用程序共享内存buffers:缓存,主要用于目录方面,inode值等 ...

  3. Spring read-only="true" 只读事务的一些概念

    概念:从这一点设置的时间点开始(时间点a)到这个事务结束的过程中,其他事务所提交的数据,该事务将看不见!(查询中不会出现别人在时间点a之后提交的数据) 应用场合: 如果你一次执行单条查询语句,则没有必 ...

  4. 小波神经网络(WNN)

    人工神经网络(ANN) 是对人脑若干基本特性通过数学方法进行的抽象和模拟,是一种模仿人脑结构及其功能的非线性信息处理系统. 具有较强的非线性逼近功能和自学习.自适应.并行处理的特点,具有良好的容错能力 ...

  5. C. Almost Equal

    C. Almost Equal n个数字全排成一个圈,满足任意相邻n个之和之间最大最小值之差不超过1 n为偶数时 不存在 n为奇数,构造 #include<bits/stdc++.h> u ...

  6. iOS-KMNavigationBarTransition 框架学习

    最后更新: 2017-06-21 一.文件结构 二.KMSwizzle KMSwizzle主要就一个方法交换的代码 2.1 class_getInstanceMethod() 获取某个类实例的方法, ...

  7. StringUtils.join()

    org.apache.commons.lang.StringUtils; StringUtils.join(null)            = null StringUtils.join([])   ...

  8. IDEA中代码不小心删除,或者改了半天想回退到某个特定时间怎么办?

    第一步: 第二步: 第三步: 第四步:

  9. 20175221曾祥杰 实验三《敏捷开发与XP实践》

    实验三<敏捷开发与XP实践> 实验报告封面 课程:Java程序设计 班级:1752班 姓名:曾祥杰 学号:20175221 指导教师:娄嘉鹏 实验日期:2019年4月30日 实验时间:13 ...

  10. scipy几乎实现numpy的所有函数

    NumPy和SciPy的关系?   numpy提供了数组对象,面向的任何使用者.scipy在numpy的基础上,面向科学家和工程师,提供了更为精准和广泛的函数.scipy几乎实现numpy的所有函数, ...