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. C#开发微信门户及应用(46)-基于Bootstrap的微信门户应用管理系统功能介绍

    在前面介绍很多的微信框架,基本上都采用EasyUI的界面来搭建的微信框架,如随笔<C#开发微信门户及应用(8)-微信门户应用管理系统功能介绍>介绍的一样,不过随着微信的H5应用越来越多,因 ...

  2. Vue.js 系列教程 1:渲染,指令,事件

    原文:intro-to-vue-1-rendering-directives-events 译者:nzbin 如果要我用一句话描述使用 Vue 的经历,我可能会说“它如此合乎常理”或者“它提供给我需要 ...

  3. .Net Core 在 Linux-Centos上的部署实战教程(四) ---- 总结

    问题: 1.网站部署上访问不了,可能是防火墙/安全组的原因 2.在后台运行这块上 我查了一些类似的部署博客 好多人都是用守护进程搞的,本人也算Linux小白  不懂这样做的好处是啥  有大佬的话  可 ...

  4. Python-类与对象

    类与对象的概念 类即类别.种类,是面向对象设计最重要的概念,从一小节我们得知对象是特征与技能的结合体,而类则是一系列对象相似的特征与技能的结合体. 那么问题来了,先有的一个个具体存在的对象(比如一个具 ...

  5. Highchartsjs使用总结及实时动态刷新图

    柱状图: $('#container').highcharts({ //突显红色柱: series: [ 523, 345, 785, 565, 843,{'color': 'red','y': 30 ...

  6. mysql实现成绩表中成绩的排名

    有这样的一个表: 如果两个分数相同,则两个分数排名(Rank)相同平分后的下一个名次应该是下一个连续的整数值. 因此,名次之间不应该有“间隔”! 此时有2种方法: 第一: select grade, ...

  7. 项目笔记-SC01

    项目启动已有两周,从分析需求到系统设计,文档性工作比较多,只是文档参考比较少,相对的标准就不好界定了. 计划开发时间理论上是按部就班的,没什么变化,可能真正进入开发阶段才会遇到一些问题吧,有些问题就是 ...

  8. python_函数名的应用、闭包、装饰器

    0.动态传参内容补充: 0.1 单纯运行如下函数不会报错. def func1(*args,**kwargs): pass func1() 0.2 *的魔性用法 * 在函数定义的时候,代表聚合. *在 ...

  9. 【kindle笔记】之 《鬼吹灯》-9-20

    [kindle笔记]读书记录-总 9-20 日常吐槽 连着几天,基本是一口气读完了鬼吹灯. 想来,也算是阴差阳错了.本来是想看盗墓的,读了几页开头,心想坏了,拷贝错了,这是鬼吹灯-- 讲真的,每每读小 ...

  10. bat 文本合并

    小工具—把多个TXT文件合成一个 - TTXS_RS的博客 - CSDN博客https://blog.csdn.net/TTXS_RS/article/details/79743384 把所有文本文件 ...