CF799B.T-shirt buying

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers p__i, a__i and b__i, where p__i is the price of the i-th t-shirt, a__i is front color of the i-th t-shirt and b__i is back color of the i-th t-shirt. All values p__i are distinct, and values a__i and b__i are integers from 1 to 3.

m buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the j-th buyer we know his favorite color c__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.

一批新的 nn 件 T 恤到货商店。每件 T 恤由三个整数 pip_i、aia_i 和 bib_i 描述:其中 pip_i 表示第 ii 件 T 恤的价格,aia_i 表示其正面颜色,bib_i 表示其背面颜色。所有价格 pip_i 互不相同,而颜色值 aia_i 和 bib_i 均为 11 到 33 之间的整数。

共有 mm 名顾客将光顾该商店,每人恰好购买一件 T 恤。对于第 jj 名顾客,已知其最喜欢的颜色为 cjc_j。

一名顾客愿意购买某件 T 恤,当且仅当该 T 恤的正面或背面至少有一面颜色等于其最喜欢的颜色。在所有满足该条件的 T 恤中,该顾客将选择价格最便宜的一件。若不存在满足条件的 T 恤,则该顾客不会购买任何商品。假设顾客按顺序依次到来,且每位顾客仅在其前一位顾客完成购买后才被服务。

请计算每位顾客最终所支付的 T 恤价格。

输入格式

The first line contains single integer n (1 ≤ n ≤ 200 000) — the number of t-shirts.

The following line contains sequence of integers _p_1, _p_2, ..., p__n (1 ≤ p__i ≤ 1 000 000 000), where p__i equals to the price of the i-th t-shirt.

The following line contains sequence of integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 3), where a__i equals to the front color of the i-th t-shirt.

The following line contains sequence of integers _b_1, _b_2, ..., b__n (1 ≤ b__i ≤ 3), where b__i equals to the back color of the i-th t-shirt.

The next line contains single integer m (1 ≤ m ≤ 200 000) — the number of buyers.

The following line contains sequence _c_1, _c_2, ..., c__m (1 ≤ c__j ≤ 3), where c__j equals to the favorite color of the j-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.

第一行包含一个整数 nn(1≤n≤200 0001 \leq n \leq 200\,000)—— 表示 T 恤的数量。

第二行包含一个整数序列 p1, p2, ..., pnp_1,\,p_2,\,...,\,p_n(1≤pi≤1 000 000 0001 \leq p_i \leq 1\,000\,000\,000),其中 pip_i 表示第 ii 件 T 恤的价格。

第三行包含一个整数序列 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n(1≤ai≤31 \leq a_i \leq 3),其中 aia_i 表示第 ii 件 T 恤正面的颜色。

第四行包含一个整数序列 b1, b2, ..., bnb_1,\,b_2,\,...,\,b_n(1≤bi≤31 \leq b_i \leq 3),其中 bib_i 表示第 ii 件 T 恤背面的颜色。

第五行包含一个整数 mm(1≤m≤200 0001 \leq m \leq 200\,000)—— 表示顾客的数量。

第六行包含一个整数序列 c1, c2, ..., cmc_1,\,c_2,\,...,\,c_m(1≤cj≤31 \leq c_j \leq 3),其中 cjc_j 表示第 jj 位顾客最喜欢的颜色。顾客按输入中给出的顺序依次来到商店。每位顾客仅在前一位顾客服务完毕后才开始接受服务。

输出格式

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

在第一行输出 m 个整数——第 j 个整数应等于第 j 个买家所购买的 T 恤的价格。如果第 j 个买家不购买任何商品,则输出 -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

输入解题思路,AI测评打分。不知道怎么写?

首页