codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

180F.md (2650B)


      1 Source: https://codeforces.com/problemset/problem/180/F
      2 
      3 F. Mathematical Analysis Rocks!
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Students of group 199 have written their lectures dismally. Now an exam on Mathematical Analysis is approaching and something has to be done asap (that is, quickly). Let's number the students of the group from 1 to *n*. Each student *i* (1 ≤ *i* ≤ *n*) has a best friend *p*[*i*] (1 ≤ *p*[*i*] ≤ *n*). In fact, each student is a best friend of exactly one student. In other words, all *p*[*i*] are different. It is possible that the group also has some really "special individuals" for who *i* = *p*[*i*].
     22 
     23 Each student wrote exactly one notebook of lecture notes. We know that the students agreed to act by the following algorithm:
     24 
     25 * on the first day of revising each student studies his own Mathematical Analysis notes,
     26 * in the morning of each following day each student gives the notebook to his best friend and takes a notebook from the student who calls him the best friend.
     27 
     28 Thus, on the second day the student *p*[*i*] (1 ≤ *i* ≤ *n*) studies the *i*-th student's notes, on the third day the notes go to student *p*[*p*[*i*]] and so on. Due to some characteristics of the boys' friendship (see paragraph 1), each day each student has exactly one notebook to study.
     29 
     30 You are given two sequences that describe the situation on the third and fourth days of revising:
     31 
     32 * *a*1, *a*2, ..., *a**n*, where *a**i* means the student who gets the *i*-th student's notebook on the third day of revising;
     33 * *b*1, *b*2, ..., *b**n*, where *b**i* means the student who gets the *i*-th student's notebook on the fourth day of revising.
     34 
     35 You do not know array *p*, that is you do not know who is the best friend to who. Write a program that finds *p* by the given sequences *a* and *b*.
     36 
     37 Input
     38 
     39 The first line contains integer *n* (1 ≤ *n* ≤ 105) — the number of students in the group. The second line contains sequence of different integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ *n*). The third line contains the sequence of different integers *b*1, *b*2, ..., *b**n* (1 ≤ *b**i* ≤ *n*).
     40 
     41 Output
     42 
     43 Print sequence *n* of different integers *p*[1], *p*[2], ..., *p*[*n*] (1 ≤ *p*[*i*] ≤ *n*). It is guaranteed that the solution exists and that it is unique.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 4  
     51 2 1 4 3  
     52 3 4 2 1
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 4 3 1 2
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 5  
     65 5 2 3 1 4  
     66 1 3 2 4 5
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 4 3 2 5 1
     73 ```
     74 
     75 Input
     76 
     77 ```
     78 2  
     79 1 2  
     80 2 1
     81 ```
     82 
     83 Output
     84 
     85 ```
     86 2 1
     87 ```