|
|||
Colors in StoreA new shipment of n tablecloths has arrived at a store. Each tablecloth is described by three attributes: price (pi), front color (ai), and back color (bi), where pi is an integer and represents the cost of the ith tablecloth, and ai and bi are integers ranging from 1 to 3, indicating the colors of the front and back of the tablecloth, respectively. It is guaranteed that all pi values are unique. The store expects m customers to visit, and each customer intends to purchase exactly one tablecloth. For each customer, we know their favorite color (cj). A customer will buy a tablecloth if either the front or back side matches their favorite color. In such cases, the customer selects the cheapest available option among the tablecloths that match their preferred color. If there are no tablecloths with an acceptable color for the customer, they won't make a purchase. The customers arrive sequentially, and each customer is served only after the previous one has been attended to. Your task is to calculate the price each customer will pay for the tablecloth they choose. Input SpecificationThe first line contains an integer n (1 ≤ n ≤ 200 000), representing the number of tablecloths. The following line provides a sequence of n integers: p1, p2, …, pn (1 ≤ pi ≤ 1 000 000 000), indicating the prices of the tablecloths. The next line contains a sequence of n integers: a1, a2, …, an (1 ≤ ai ≤ 3), representing the front colors of the tablecloths. The subsequent line contains a sequence of n integers: b1, b2, …, bn (1 ≤ bi ≤ 3), indicating the back colors of the tablecloths. Then, there's a single integer m (1 ≤ m ≤ 200 000), denoting the number of customers. The next line provides a sequence of m integers: c1, c2, …, cm (1 ≤ cj ≤ 3), signifying the favorite color of each customer. The customers arrive in the order they are listed in the input, and each customer is served only after the previous one has been assisted. Output SpecificationPrint one line to the standard output with m space-separated integers, where the jth integer should represent the price of the tablecloth that the jth customer will purchase. If the jth customer decides not to buy anything, print –1 for that customer. Sample Input
Output for Sample Input
|
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |