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 (1≤n≤2000001≤n≤200000) — the number of rows in the bus.

The second line contains the sequence of integers w1,w2,…,wnw1,w2,…,wn (1≤wi≤1091≤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.

在角色巴士中有n排座位,每排都有2个座位。 第i排的两个座位的宽度均为w i厘米。 没有相同宽度的座椅。
 
公共汽车最初是空的。 每个2n站都会有一位乘客进入巴士。 有两种类型的乘客:
 
  • 一个内向者总是选择两个座位都没人的一排。 在这些排中,他选择座位宽度最小的,并占据了其中的一个座位;
  • 一个外向型的人总是选择有人的一排。 在这些排中,他选择了座位宽度最大的那个,并占据了空位。
 
你会得到每排座位的宽度和乘客进入公共汽车的顺序。 确定每位乘客将乘坐哪一排。

Input

第一行包含一个整数n(1 ≤ n ≤ 200000) - 总排数。
 
第二行包含整数w 1,w 2,...,w n(1 ≤ w ≤ 10 9)的序列,其中wi是第i行中每个座位的宽度。 保证所有 w 都不同。
 
第三行包含一个长度为 2n 的字符串,由数字“0”和“1”组成 - 描述乘客进入公共汽车的顺序。 如果第j个字符是 '0',那么在第 j 个车站进入公共汽车的乘客是内向的。 如果第j个字符是 '1',则在第j个车站进入公交车的乘客是外向型的。 保证外向者的数量等于内向者的数量(即两个数字等于 n),并且对于每个外向者总是有合适的行。

Output

打印 2n 个整数 - 乘客将坐的排。 乘客的顺序应与输入的顺序相同。

Sample Input

Input

2
3 1
0011

Output

2 1 1 2 

Input

6
10 8 9 11 13 5
010010011101

Output

6 6 2 3 3 1 4 4 1 2 5 5

Hint

在第一个例子中,第一个乘客(内向)选择第二排,因为它具有最小宽度的座位。 第二位乘客(内向)选择第1行,因为它现在是唯一的空行。 第三位乘客(外向型)选择第一排,因为它只有一个占用的座位,座位宽度是这些排中最大的。 第四位乘客(外向性)选择第二排,因为它是唯一一个有空位的排。

解题思路:我们知道内向的人会去选择那些空位并且宽度最小的座位,而外向的人却是选择有人的座位边的座位并且尽可能的座位宽度要大,这里其实是可以使用一个栈来模拟的,根据题目所给的信息,我们可以知道,肯定是先有内向的人上车再有外向的人上车,内向人上车就可以看做一个入栈的过程,记录内向人的座号,外向人上车必然会选择之前内向人做过的排位,而恰到好处的是这个题目的要求,内向人尽可能地选择宽度小的座位,而外向人尽可能选择宽度大的座位,在这里就可以现将座位的宽度升序排序,使内向上车的人尽可能得到宽度小的座位,而外向上车的人会得到靠近内向人并且座位宽度尽可能大的座位(栈中的第一个元素)

#include<stdio.h>
#include<algorithm>
#include<stack>
using namespace std;
struct node
{
int val;
int idx;
} a[200010];
char x[400010];
int my_cmp(node a,node b)
{
if(a.val<b.val)
return 1;
else
return 0;
}
stack<node>s;
int main()
{
int n,i,j;
struct node k;
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d",&a[i].val);
a[i].idx=i;
}
sort(a,a+n,my_cmp);
getchar();
gets(x);
j=0;
for(i=0; i<2*n; i++)
{
if(x[i]=='0')
{
s.push(a[j]);
j++;
printf("%d ",a[j-1].idx+1);
}
else
{
k=s.top();
printf("%d ",k.idx+1);
s.pop();
}
}
return 0;
}

  

Bus of Characters(栈和队列)的更多相关文章

  1. [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)

    再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...

  2. Swift 算法实战之路:栈和队列

    这期的内容有点剑走偏锋,我们来讨论一下栈和队列.Swift语言中没有内设的栈和队列,很多扩展库中使用Generic Type来实现栈或是队列.笔者觉得最实用的实现方法是使用数组,本期主要内容有: 栈和 ...

  3. Codeforces Round #484 (Div. 2) B. Bus of Characters(STL+贪心)982B

    原博主:https://blog.csdn.net/amovement/article/details/80358962 B. Bus of Characters time limit per tes ...

  4. 学习javascript数据结构(一)——栈和队列

    前言 只要你不计较得失,人生还有什么不能想法子克服的. 原文地址:学习javascript数据结构(一)--栈和队列 博主博客地址:Damonare的个人博客 几乎所有的编程语言都原生支持数组类型,因 ...

  5. 剑指Offer面试题:6.用两个栈实现队列

    一.题目:用两个栈实现队列 题目:用两个栈实现一个队列.队列的声明如下,请实现它的两个函数appendTail和deleteHead,分别完成在队列尾部插入结点和在队列头部删除结点的功能. 原文是使用 ...

  6. C实现栈和队列

    这两天再学习了数据结构的栈和队列,思想很简单,可能是学习PHP那会没有直接使用栈和队列,写的太少,所以用具体代码实现的时候出现了各种错误,感觉还是C语言功底不行.栈和队列不论在面试中还是笔试中都很重要 ...

  7. JavaScript数组模拟栈和队列

    *栈和队列:js中没有真正的栈和队列的类型              一切都是用数组对象模拟的 栈:只能从一端进出的数组,另一端封闭       FILO   何时使用:今后只要仅希望数组只能从一端进 ...

  8. 用JS描述的数据结构及算法表示——栈和队列(基础版)

    前言:找了上课时数据结构的教程来看,但是用的语言是c++,所以具体实现在网上搜大神的博客来看,我看到的大神们的博客都写得特别好,不止讲了最基本的思想和算法实现,更多的是侧重于实例运用,一边看一边在心里 ...

  9. JavaScript中的算法之美——栈、队列、表

    序 最近花了比较多的时间来学习前端的知识,在这个期间也看到了很多的优秀的文章,其中Aaron可能在这个算法方面算是我的启蒙,在此衷心感谢Aaron的付出和奉献,同时自己也会坚定的走前人这种无私奉献的分 ...

随机推荐

  1. Linux学习笔记——1.超级用户

    以超级用户工作:su su命令允许临时变换到任何一用户标识(如果拥有口令的话),并挂起当前shell,为新用户开启一个新的shell. su <user> 将当前用户标识harley变换为 ...

  2. javascript最常用的对象创建方式

    //第一种 function Demo(){ var obj=new Object(); obj.name="Yubaba"; obj.age=12; obj.firstF=fun ...

  3. 关于CoreLocation定位服务的简单使用

    在我们发微博,发表空间内容,以及在朋友圈发表动态的时候,会发现有一个位置信息的控件.iOS中是如何定位我们的位置信息的呢?基于此写一个小Demo,供大家参考使用. 在iOS中,用于定位时需要我们导入以 ...

  4. [Java]Java 9运行Spring Boot项目报错的解决办法

    简介 为了学习和尽快掌握 Java 9 的模块化(Module System)新特性,最近安装了 JDK 9,新建了一个 Spring Boot 进行尝试, 过程中遇到了一下报错问题,写下此文谨作为个 ...

  5. sql server 常用sql语句

    --删除约束 alter table productInfo drop constraint 约束名称 --删除列alter table productInfo drop column 列名 --添加 ...

  6. HttpClient的Content-Type设置

    HttpClient的Content-Type设置 最近在对接公司内容的一个云服务的时候,遇到一个问题,就是如果使用HttpClient如何设置post时候的Content-Type? public ...

  7. HyperLedger Fabric 1.4 基础环境搭建(7)

    学习了前面几章理论知识后,本章开始介绍实践操作,先介绍Fabric基础环境搭建,采用的操作系统为Centos 7 64位,依次介绍Docker安装.Docker-Compose安装.GO语言环境安装. ...

  8. 成都Uber优步司机奖励政策(1月18日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  9. 1 多任务fork Unix/Linux/Mac

    # 注意,fork函数,只在Unix/Linux/Mac上运行,windows不可以 1.如下程序,来模拟“唱歌跳舞”这件事情 #-*- coding:utf-8 -*- import time de ...

  10. STM32的GUI库使用

    1. 实验平台使用百为的STM32F103开发板 2. 例程目录\百为stm32开发板光盘\stm32_gui_lib\Project\Embedded_GUI_Example\EWARM 3. 直接 ...