Pasha and String

CodeForces - 525B

Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string.

Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent m days performing the following transformations on his string — each day he chose integer ai and reversed a piece of string (a segment) from position ai to position |s| - ai + 1. It is guaranteed that 2·ai ≤ |s|.

You face the following task: determine what Pasha's string will look like after mdays.

Input

The first line of the input contains Pasha's string s of length from 2 to 2·105characters, consisting of lowercase Latin letters.

The second line contains a single integer m (1 ≤ m ≤ 105) —  the number of days when Pasha changed his string.

The third line contains m space-separated elements ai (1 ≤ ai; 2·ai ≤ |s|) — the position from which Pasha started transforming the string on the i-th day.

Output

In the first line of the output print what Pasha's string s will look like after mdays.

Examples

Input
abcdef
1
2
Output
aedcbf
Input
vwxyz
2
2 2
Output
vwxyz
Input
abcdef
3
1 2 3
Output
fbdcea

sol:题意:给出一个字符串,读入ai,表示翻转区间[ai,n-ai+1]
Ps:写splay的大佬可以直接去码splay,不用看下面的XJB做法
易知:每个位置翻转两次就相当于没变,于是处理出每个位置翻转的次数,差分就可以了,然后从1~n/2扫一遍,对于操作次数是奇数的位置与对应的位置交换
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,Q;
char S[N];
int Sum[N];
int main()
{
int i;
scanf("%s",S+); n=strlen(S+);
R(Q);
for(i=;i<=Q;i++)
{
int x=read();
Sum[x]++;
Sum[n-x+]--;
}
for(i=;i<=n;i++)
{
Sum[i]+=Sum[i-];
}
for(i=;i<=(n/);i++) if(Sum[i]&)
{
swap(S[i],S[n-i+]);
}
for(i=;i<=n;i++) putchar(S[i]);
puts("");
return ;
}
/*
input
abcdef
1
2
output
aedcbf input
vwxyz
2
2 2
output
vwxyz input
abcdef
3
1 2 3
output
fbdcea input
keicnqmuqinhsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavs
2
5 12
output
keiccyobhhphsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlniqumqnfavs
*/
 

codeforces525B的更多相关文章

随机推荐

  1. MVC架构在Asp.net中的应用和实现

    转载自:http://www.cnblogs.com/baiye7223725/archive/2007/06/07/775390.aspx 摘要:本文主要论述了MVC架构的原理.优缺点以及MVC所能 ...

  2. Unity热更新学习(一) —— AssetBundle 打包和加载

    理论不多说,网上,官方文档都有.  这里有一篇介绍很全面的文章:https://www.cnblogs.com/ybgame/p/3973177.html 示例和注意点记录一下,用到时以便查阅. 一. ...

  3. 开启Tomcat的manager页面访问

    如何进入Tomcat的manager页面 一张图解决! 找到conf目录下的tomcat-users.xml文件,打开. <role rolename="admin-gui" ...

  4. Linux、Windows如何进行性能监控与调优

    1.Linux命令行工具 推荐:CentOS 7 1.1 top命令 top命令的输出如下: top命令的输出可以分为两部分:前半部分是系统统计信息,后半部分是进程信息.在统计信息中, 第1行是任务队 ...

  5. nrf2401 - 最廉价的2.4G无线通信方案

    所有的使用Arduino 的朋友大多都会知道大名鼎鼎的XBee 这个土豪级的ZigBee 的通信模块.我们是做产品开发的,对于XBee这个产品可谓是又爱又恨,不得不承认他确实是一个好货,从做工到功能都 ...

  6. Webpack+Typescript 简易配置

    教程:https://www.cnblogs.com/yasepix/p/9294499.html http://developer.egret.com/cn/github/egret-docs/ex ...

  7. Minesweeper

    你玩过扫雷吗?这个可爱的小游戏带有一个我们记不住名字的操作系统.游戏的目标是找到所有地雷在M x N场中的位置.游戏在一个正方形中显示一个数字,它告诉你在这个正方形附近有 多少个地雷.每个方块最多有八 ...

  8. vue-cli脚手架安装和webpack-simple模板项目生成

    vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue-cli 可以快速创建 vue 项目. GitHub地址是:https://github.com/vuejs/vue-cli 一. ...

  9. VO和DO转换(四) MapStruct

    VO和DO转换(一) 工具汇总 VO和DO转换(二) BeanUtils VO和DO转换(三) Dozer VO和DO转换(四) MapStruct MapStruct

  10. 多线程系列之六:Producer-Consumer模式

    一,Producer-Consumer模式 Producer:生产者的意思,指的是生成数据的线程.Consumer:消费者的意思,指的是使用数据的线程当生产者和消费者以不同的线程运行时,两者之间的处理 ...