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. .frm和.ibd恢复数据

    昨日晚上开发告诉我不小心truncate两个表的数据,要求还原.结果在阿里云上找到了备份内容,结果是物理备份文件.frm..ibd.心中一万个草泥马啊..没办法,开始还原吧. 1.查看测试机Mysql ...

  3. 误删重要文件怎么办?学会Linux 救援模式再也不担心

    背景 在运用Linux时会出现一些误操作,导致系统无法正常使用,比如删除了某个重要依赖库,或者删除了rpm等等.在这里记录下具体的操作步骤,供以后参考. 意义 学会在使用Linux系统出现误删除系统重 ...

  4. mongoose的安装与使用(书签记录) 2017

    Windows7环境下安装:慕课网中的手记 http://www.imooc.com/article/12447 关于在CMD中对Mongo API的调用,从这些API调用中我们也可以更容易地理解在n ...

  5. Ubuntu下rsyslog审计用户bash操作命令、收集、写入MySQL

    服务端 2台服务端:10.25.109.64.10.45.18.133 1.rsyslog最新版本安装 sudo add-apt-repository ppa:adiscon/v8-stable su ...

  6. BZOJ 3796 Mushroom追妹纸 哈希+二分(+KMP)

    先把两个串能匹配模式串的位置找出来,然后标记为$1$(标记在开头或末尾都行),然后对标记数组求一个前缀和,这样可以快速查到区间内是否有完整的一个模式串. 然后二分子串(答案)的长度,每次把长度为$md ...

  7. 装饰器(Decorator)模式

    public interface IDoThings { public void doSomeThing(); } public class DoThings implements IDoThings ...

  8. mask

    select ) as cnt from ( ' as flag union all select 'a' as flag union all select null as flag ) t0 ; s ...

  9. View转换为Bitmap及getDrawingCache

    View组件显示的内容可以通过cache机制保存为bitmap, 使用到的api有 void  setDrawingCacheEnabled(boolean flag),    Bitmap  get ...

  10. Oracle视图,索引,序列

    什么是视图[View] (1)视图是一种虚表 (2)视图建立在已有表的基础上, 视图赖以建立的这些表称为基表(3)向视图提供数据内容的语句为 SELECT 语句,可以将视图理解为存储起来的 SELEC ...