B. Bus of Characters

B. Bus of Characters
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In the Bus of Characters there are nn rows of seat, each having 22 seats. The width of both seats in the ii-th row is wiwi centimeters. All integers wiwi are distinct.

Initially the bus is empty. On each of 2n2n 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.

Input

The first line contains a single integer nn (1n2000001≤n≤200000) — the number of rows in the bus.

The second line contains the sequence of integers w1,w2,,wnw1,w2,…,wn (1wi1091≤wi≤109), where wiwi is the width of each of the seats in the ii-th row. It is guaranteed that all wiwi are distinct.

The third line contains a string of length 2n2n, consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the jj-th character is '0', then the passenger that enters the bus on the jj-th stop is an introvert. If the jj-th character is '1', the the passenger that enters the bus on the jj-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal nn), and for each extrovert there always is a suitable row.

Output

Print 2n2n integers — the rows the passengers will take. The order of passengers should be the same as in input.

Examples
input
Copy
2
3 1
0011
output
Copy
2 1 1 2 
input
Copy
6
10 8 9 11 13 5
010010011101
output
Copy
6 6 2 3 3 1 4 4 1 2 5 5 
Note

In the first example the first passenger (introvert) chooses the row 22, because it has the seats with smallest width. The second passenger (introvert) chooses the row 11, because it is the only empty row now. The third passenger (extrovert) chooses the row 11, because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row 22, because it is the only row with an empty place.

这个题的大意就是:每一列座位可以做两个人。已知有两种人,第一种人是在两个座位都是空的条件下,做尺寸偏小的哪一个。第二种人是在两个座位中有一个座位已经有人的前提下,做尺寸偏大的那一个。

输入座位的排数,以及每一排座位的尺寸,以及上车的人的类型,然后让你输出每一个上车的人的选择。

具体思路:对于第一种人而言,只是选空座位中最小的那一个,所以我们可以将空座位打进结构体里面,对于第二种人,因为有座位的排数是逐渐增加的,每一次增加都需要从中选择出尺寸最大的那一个,所以可以将有座位的排数打进优先队列里。

代码如下:

#include<bits/stdc++.h>
using namespace std;
char str[400001];
struct node
{
    int wi;
    int id;
    bool friend operator < (const node u,const node v)
    {
        return u.wi<v.wi;
    }//这个地方有些疑问,优先队列里面需要进行降序,正常的话应该是">"号,为什么这里是"<"号?是因为这个是队列,然后输出的时候是从底部开始的原因?
} q[200001];
bool cmp(const node u,const  node v)
{
    return u.wi<v.wi;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>q[i].wi;
        q[i].id=i;
    }
    priority_queue<node >p;
    sort(q+1,q+n+1,cmp);//对空座位进行排序
    cin>>str+1;
    int t=1;
    for(int i=1; i<=2*n; i++)
    {
        if(str[i]=='0')
        {
            cout<<q[t].id;
            p.push(q[t++]);//每当有一个空座位做上人的时候,这排座位就变成了第二种情况,所以需要把这个座位放进优先队列里
        }
        if(str[i]=='1')
        {
            cout<<p.top().id;
            p.pop();
        }
        if(i!=2*n)
            cout<<" ";
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/let_life_stop/article/details/80399849