https://codeforces.com/contest/1157/problem/B
题意:用给定的代替数组,替换数字字符串的一段连续的区间,使得数字字符串字典序最大
题解:找到第一个替换以后字典序增加的字符,开始连续替换,直到字符串结尾或者替换以后小于之前一个字符串
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=200000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int ans,cnt,flag,temp,sum;
int a[N],b[N];
char str[N];
struct node{};
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
//scanf("%d",&t);
//while(t--){
scanf("%d",&n);
cin>>str;
for(int i=0;i<n;i++){
a[i]=str[i]-'0';
}
for(int i=1;i<=9;i++){
scanf("%d",&b[i]);
}
for(int i=0;i<n;i++){
if(flag){
if(b[a[i]]>=a[i]){
a[i]=b[a[i]];
}else{
break;
}
}else{
if(b[a[i]]>a[i]){
a[i]=b[a[i]];
flag=1;
}
}
}
for(int i=0;i<n;i++){
cout<<a[i];
}
cout<<endl;
//}
#ifdef DEBUG
printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
//cout << "Hello world!" << endl;
return 0;
}