CF1154E.Two Teams
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
有 n 名学生站成一排。两名教练正在组建两支队伍——第一位教练选择第一支队伍,第二位教练选择第二支队伍。
第 i 名学生的编程技能为整数 ai。所有编程技能互不相同,且均在 1 到 n(含)之间。
首先,第一位教练将在所有尚未被选入任何队伍的学生中,选出编程技能最高的那名学生,并同时选出该学生左侧最近的 k 名学生以及右侧最近的 k 名学生(若左侧或右侧的学生不足 k 名,则将所有可用学生全部选出)。所有被选中的学生将离开队列,加入第一支队伍。接着,第二位教练执行相同的步骤(但所有被他选中的学生加入第二支队伍)。然后再次由第一位教练执行该步骤,依此类推。该过程不断重复,直至队列为空(即当每名学生都被分配至某支队伍时,过程结束)。
你的任务是确定哪些学生将被选入第一支队伍,哪些学生将被选入第二支队伍。
输入格式
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.
输入的第一行包含两个整数 n 和 k(1≤k≤n≤2⋅105),分别表示学生的数量以及每次操作中所选学生范围的参数值。
输入的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n),其中 ai 表示第 i 个学生的编程技能。保证所有编程技能值互不相同。
输出格式
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
输出一个长度为 n 的字符串;其中第 i 个字符应为 1(如果第 i 名学生加入第一支队伍),否则为 2。
输入输出样例
输入#1
5 2 2 4 5 3 1
输出#1
11111
输入#2
5 1 2 1 3 5 4
输出#2
22111
输入#3
7 1 7 2 1 3 5 4 6
输出#3
1121122
输入#4
5 1 2 4 5 3 1
输出#4
21112
说明/提示
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).
在第一个例子中,第一位教练选择了位置 3 上的学生,队伍变为空(所有学生都加入了第一支队伍)。
在第二个例子中,第一位教练选择了位置 4 上的学生,队伍变为 [2,1](编程能力为 [3,4,5] 的学生加入了第一支队伍)。接着,第二位教练选择了位置 1 上的学生,队伍变为空(编程能力为 [1,2] 的学生加入了第二支队伍)。
在第三个例子中,第一位教练选择了位置 1 上的学生,队伍变为 [1,3,5,4,6](编程能力为 [2,7] 的学生加入了第一支队伍)。接着,第二位教练选择了位置 5 上的学生,队伍变为 [1,3,5](编程能力为 [4,6] 的学生加入了第二支队伍)。然后,第一位教练选择了位置 3 上的学生,队伍变为 [1](编程能力为 [3,5] 的学生加入了第一支队伍)。最后,第二位教练选择了剩下的那名学生(编程能力为 1 的学生加入了第二支队伍)。
在第四个例子中,第一位教练选择了位置 3 上的学生,队伍变为 [2,1](编程能力为 [3,4,5] 的学生加入了第一支队伍)。接着,第二位教练选择了位置 1 上的学生,队伍变为空(编程能力为 [1,2] 的学生加入了第二支队伍)。
输入解题思路,AI测评打分。不知道怎么写?