Stevie !
Practice
2.5 (32 votes)
Easy
Maps
Problem
53% Success 8808 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Stevie G is one of the greatest ever players to have played football, and he's going to be the one who recites all problems to you today . Let's have a look at him :

                                                                             enter image description here

Now, he is a true admirer of mathematical geniuses like you. So he has a series of programming problems, among which the first one is :

You have been given 2 integer arrays A and B each of size N. Now we call a pair of indices \((i,j)\) connected, if \(i = j\) or \( A[i] = A[j] \) .

Now, for each index i in the array A where \( 1 \le i \le N \), you need to find the maximum \(B[j]\) such that indices i and j are connected. Can you do it ?

Input Format :

The first line contains a single integer N.

The next line contains N space separated integers, where the \(i^{th}\) integer denotes \(A[i]\). The next line too contains N space separated integers, where the \(i^{th}\) integer on this line denotes \(B[i]\).

Output Format :

Print N space separated integers according to those mentioned in the problem statement.

Constraints :

\( 1 \le N \le 200,000 \)

\( 1 \le A[i], B[i] \le 10^9 \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
38 votes
Tags:
ApprovedEasyGeometryMathOpen
Points:20
17 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementation
Points:20
495 votes
Tags:
ApprovedData StructuresEasyImplementation