A11851 | Bus of Characters
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$ -th row is $w_i$ centimeters. All integers $w_i$ are distinct.
Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers:
- an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it;
- an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it.
You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.
Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers:
- an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it;
- an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it.
You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.
输入格式
The first line contains a single integer $n$ ( $1 \le n \le 200\,000$ ) — the number of rows in the bus.
The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ( $1 \le w_i \le 10^{9}$ ), where $w_i$ is the width of each of the seats in the $i$ -th row. It is guaranteed that all $w_i$ are distinct.
The third line contains a string of length $2n$ , consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the $j$ -th character is '0', then the passenger that enters the bus on the $j$ -th stop is an introvert. If the $j$ -th character is '1', the the passenger that enters the bus on the $j$ -th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal $n$ ), and for each extrovert there always is a suitable row.
The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ( $1 \le w_i \le 10^{9}$ ), where $w_i$ is the width of each of the seats in the $i$ -th row. It is guaranteed that all $w_i$ are distinct.
The third line contains a string of length $2n$ , consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the $j$ -th character is '0', then the passenger that enters the bus on the $j$ -th stop is an introvert. If the $j$ -th character is '1', the the passenger that enters the bus on the $j$ -th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal $n$ ), and for each extrovert there always is a suitable row.
输出格式
Print $2n$ integers — the rows the passengers will take. The order of passengers should be the same as in input.
输入输出样例
输入 #1
2 3 1 0011
输出 #1
2 1 1 2
输入 #2
6 10 8 9 11 13 5 010010011101
输出 #2
6 6 2 3 3 1 4 4 1 2 5 5
In the first example the first passenger (introvert) chooses the row $2$ , because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$ , because it is the only empty row now. The third passenger (extrovert) chooses the row $1$ , because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row $2$ , because it is the only row with an empty place.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted