多重映射

多重映射

https://ac.nowcoder.com/acm/contest/75771/E

#include<bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
const int mod  = 1e9 + 7;
void solve(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n+1,0),l(m+10),r(m+10);
    map<int,int> mp;
    for (int i = 1; i <= n; ++i) {
        cin>>a[i];
        mp[a[i]] = a[i];
    }
    for (int k = 1; k <= m; ++k) {
        cin>>l[k]>>r[k];
        mp[l[k]] = l[k];
        mp[r[k]] = r[k];
    }
    for (int i = m; i >= 1 ; --i) {
        mp[l[i]] = mp[r[i]];
    }
    for (int i = 1; i <= n; ++i) {
        a[i] = mp[a[i]];
        cout<<a[i]<<" ";
    }
    cout<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t = 1;
    cin>>t;
    while(t--){
        solve();//1 2 3 4 5
    }
    return 0 ;
}



全部评论

相关推荐

求offer的大角牛:简历写的第一乱,没有突出重点,第二项目太多太杂看不出来有啥核心技术,第三自我评价太多了,第四获得的荣誉没啥含金量,可以不写,反正问题不少
点赞 评论 收藏
分享
盖茨伯爵:一样兄弟,我从4月开始发到现在了,都三四百个了
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务