CF982B.Bus of Characters
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 wi centimeters. All integers wi 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.
在“字符巴士”中有 n 排座位,每排有 2 个座位。第 i 排两个座位的宽度均为 wi 厘米。所有整数 wi 互不相同。
初始时巴士为空。在总共 2n 个站点中,每个站点恰有一名乘客上车。乘客分为两类:
- 内向型乘客:总是选择一排两个座位均为空的座位;在所有满足条件的排中,他选择座位宽度最小的那一排,并占据该排中的一个座位;
- 外向型乘客:总是选择一排恰好有一个座位已被占用(且该座位必由一名内向型乘客占据)的座位;在所有满足条件的排中,他选择座位宽度最大的那一排,并占据该排中空余的那个座位。
已知每排座位的宽度以及乘客上车的顺序,请确定每位乘客所选择的排号。
输入格式
The first line contains a single integer n (1≤n≤200000) — the number of rows in the bus.
The second line contains the sequence of integers w1,w2,…,wn (1≤wi≤109), where wi is the width of each of the seats in the i-th row. It is guaranteed that all wi 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.
第一行包含一个整数 n(1≤n≤200000),表示公交车的行数。
第二行包含一个长度为 n 的整数序列 w1,w2,…,wn(1≤wi≤109),其中 wi 表示第 i 行中每个座位的宽度。保证所有 wi 互不相同。
第三行包含一个长度为 2n 的字符串,仅由字符 '0' 和 '1' 组成,描述乘客上车的顺序。若第 j 个字符为 '0',则在第 j 站上车的乘客为内向型乘客;若为 '1',则为外向型乘客。保证外向型乘客的数量等于内向型乘客的数量(即二者均为 n),且对每位外向型乘客,总存在一个合适的行可供选择。
输出格式
Print 2n integers — the rows the passengers will take. The order of passengers should be the same as in input.
输出 2n 个整数——乘客将乘坐的行号。乘客的顺序应与输入中的顺序一致。
输入输出样例
输入#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.
在第一个例子中,第一位乘客(内向型)选择了第 2 行,因为该行的座位宽度最小。第二位乘客(内向型)选择了第 1 行,因为此时它是唯一空着的行。第三位乘客(外向型)选择了第 1 行,因为该行恰好有一个已被占用的座位,且在所有满足此条件的行中,其座位宽度最大。第四位乘客(外向型)选择了第 2 行,因为它是唯一还有空位的行。
输入解题思路,AI测评打分。不知道怎么写?