A12474 | Two Teams
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $a_i$ . 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.
The $i$ -th student has integer programming skill $a_i$ . 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.
输入格式
The first line of the input contains two integers $n$ and $k$ ( $1 \le k \le n \le 2 \cdot 10^5$ ) — 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 $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le n$ ), where $a_i$ is the programming skill of the $i$ -th student. It is guaranteed that all programming skills are distinct.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le n$ ), where $a_i$ is the programming skill of the $i$ -th student. It is guaranteed that all programming skills are distinct.
输出格式
Print a string of $n$ characters; $i$ -th character should be 1 if $i$ -th student joins the first team, or 2 otherwise.
输入输出样例
输入 #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).
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).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted