CF799B.T-shirt buying

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A new pack of nn t-shirts came to a shop. Each of the t-shirts is characterized by three integers pip_{i} , aia_{i} and bib_{i} , where pip_{i} is the price of the ii -th t-shirt, aia_{i} is front color of the ii -th t-shirt and bib_{i} is back color of the ii -th t-shirt. All values pip_{i} are distinct, and values aia_{i} and bib_{i} are integers from 11 to 33 .

mm buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the jj -th buyer we know his favorite color cjc_{j} .

A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won't buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served.

You are to compute the prices each buyer will pay for t-shirts.

输入格式

The first line contains single integer nn ( 1<=n<=2000001<=n<=200000 ) — the number of t-shirts.

The following line contains sequence of integers p1,p2,...,pnp_{1},p_{2},...,p_{n} ( 1<=pi<=10000000001<=p_{i}<=1000000000 ), where pip_{i} equals to the price of the ii -th t-shirt.

The following line contains sequence of integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=31<=a_{i}<=3 ), where aia_{i} equals to the front color of the ii -th t-shirt.

The following line contains sequence of integers b1,b2,...,bnb_{1},b_{2},...,b_{n} ( 1<=bi<=31<=b_{i}<=3 ), where bib_{i} equals to the back color of the ii -th t-shirt.

The next line contains single integer mm ( 1<=m<=2000001<=m<=200000 ) — the number of buyers.

The following line contains sequence c1,c2,...,cmc_{1},c_{2},...,c_{m} ( 1<=cj<=31<=c_{j}<=3 ), where cjc_{j} equals to the favorite color of the jj -th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served.

输出格式

Print to the first line mm integers — the jj -th integer should be equal to the price of the t-shirt which the jj -th buyer will buy. If the jj -th buyer won't buy anything, print -1.

输入输出样例

  • 输入#1

    5
    300 200 400 500 911
    1 2 1 2 3
    2 1 3 2 1
    6
    2 3 1 2 1 1
    

    输出#1

    200 400 300 500 911 -1 
    
  • 输入#2

    2
    1000000000 1
    1 1
    1 2
    2
    2 1
    

    输出#2

    1 1000000000 
    
首页