O(1)变换映射,最后一次性替换。

#include<bits/stdc++.h>
using namespace std; typedef long long ll; const int LEN = 2e5+;
char s[LEN];
char mp[];
int pos[];
//#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
for(int i = ; i < ; i++) pos[i] = i;
int n, m; scanf("%d%d%s",&n,&m,s);
while(m--){
char x[], y[]; scanf("%s %s", x, y);
swap(pos[*x-'a'], pos[*y-'a']);
}
for(int i = ; i < ; i++) mp[pos[i]] = i+'a';
for(int i = ; i < n; i++) putchar(mp[s[i]-'a']);
return ;
}

Codeforces Round #327 (Div. 2) B Rebranding(映射)的更多相关文章

  1. Codeforces Round #327 (Div. 2) B. Rebranding C. Median Smoothing

    B. Rebranding The name of one small but proud corporation consists of n lowercase English letters. T ...

  2. Codeforces Round #327 (Div. 2) B. Rebranding 水题

    B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...

  3. Codeforces Round #327 (Div. 2) B. Rebranding 模拟

    B. Rebranding   The name of one small but proud corporation consists of n lowercase English letters. ...

  4. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  5. Codeforces Round #327 (Div. 2)B(逻辑)

    B. Rebranding time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #327 (Div. 2)

    题目传送门 水 A - Wizards' Duel 题目都没看清就写了,1e-4精度WA了一次... /************************************************ ...

  7. Codeforces Round #327 (Div. 2) E. Three States BFS

    E. Three States Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/probl ...

  8. Codeforces Round #327 (Div. 2) D. Chip 'n Dale Rescue Rangers 二分 物理

    D. Chip 'n Dale Rescue Rangers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...

  9. Codeforces Round #327 (Div. 2) C. Median Smoothing 找规律

    C. Median Smoothing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/p ...

随机推荐

  1. SAS笔记(2) RETAIN语句

    本文重点: 使用RETIAN,INPUT在每次循环执行时保留上一次PDV中的变量值. SUM语句和SET语句会自动RETAIN变量. 1. RETAIN语句 1.1 Example 1 先来看看在DA ...

  2. 打通Java与MySQL的桥梁——jdbc

    实现的基本步骤: 1.加载驱动程序: Class.forName("com.mysql.jdbc.Driver"); 2.获得数据可连接: private static final ...

  3. tp5.1 手动引入外部类库

    use think\facade\Env; require_once Env::get('ROOT_PATH')."extend/PHPExcel/Classes/PHPExcel.php& ...

  4. Anniversary party (树形DP)

    There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The Un ...

  5. Duff and Meat(贪心)

    Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day ...

  6. jasper_excel_sheet tab color

    <property name="net.sf.jasperreports.export.xls.sheet.tab.color" value="#00FF00&qu ...

  7. ssh无需密码登录linux服务器

    使用下例中ssky-keygen和ssh-copy-id,仅需通过3个步骤的简单设置而无需输入密码就能登录远程Linux主机. ssh-keygen 创建公钥和密钥. ssh-copy-id 把本地主 ...

  8. Ubuntu安装LAMP环境(PHP5.6) 以及下载安装phpmyadmin

    参考路径: http://blog.nciaer.com/?p=133 修改apache(2.4.18)的web路径时, 需要将 /etc/apache2/sites-available/000def ...

  9. mysql语句删除重复数据,保留一条;查询所有重复数据;查询重复数据的一条,

    //显示重复的所有条 SELECT * FROM 表名 WHERE (字段1,字段2,...) IN (SELECT 字段1,字段2,...FROM 表名 GROUP BY 字段1,字段2,... H ...

  10. (转载)ASP.NET Quiz Answers: Does Page.Cache leak memory?

    原文地址:http://blogs.msdn.com/b/tess/archive/2006/08/11/695268.aspx "We use Page.Cache to store te ...