Long Number
题意翻译
## 题目描述
给定一个一个n位数,以及1~9数字的替换数。现请你在这个n位数上选一个连续的数段,将段内的每个数字替换成相应数字的替换数。要求:输出按照要求替换后的最大n位整数。
## 输入输出格式
### 输入格式:
第一行一个整数n$ ( 1 \le n \le 2 \cdot 10^5 ) $
第二行一个n位整数
第三行为9个替换数(一位正整数),第i个为数字i的替换数
### 输出格式:
一个n位整数,即按照要求替换后你的最大结果
题目描述
You are given a long decimal number $ a $ consisting of $ n $ digits from $ 1 $ to $ 9 $ . You also have a function $ f $ that maps every digit from $ 1 $ to $ 9 $ to some (possibly the same) digit from $ 1 $ to $ 9 $ .
You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in $ a $ , and replace each digit $ x $ from this segment with $ f(x) $ . For example, if $ a = 1337 $ , $ f(1) = 1 $ , $ f(3) = 5 $ , $ f(7) = 3 $ , and you choose the segment consisting of three rightmost digits, you get $ 1553 $ as the result.
What is the maximum possible number you can obtain applying this operation no more than once?
输入输出格式
输入格式
The first line contains one integer $ n $ ( $ 1 \le n \le 2 \cdot 10^5 $ ) — the number of digits in $ a $ .
The second line contains a string of $ n $ characters, denoting the number $ a $ . Each character is a decimal digit from $ 1 $ to $ 9 $ .
The third line contains exactly $ 9 $ integers $ f(1) $ , $ f(2) $ , ..., $ f(9) $ ( $ 1 \le f(i) \le 9 $ ).
输出格式
Print the maximum number you can get after applying the operation described in the statement no more than once.
输入输出样例
输入样例 #1
4
1337
1 2 5 4 6 6 3 1 9
输出样例 #1
1557
输入样例 #2
5
11111
9 8 7 6 5 4 3 2 1
输出样例 #2
99999
输入样例 #3
2
33
1 1 1 1 1 1 1 1 1
输出样例 #3
33