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. Kubernetes学习之路(26)之kubeasz+ansible部署集群

    目录 1.环境说明 2.准备工作 3.分步骤安装 3.1.创建证书和安装准备 3.2.安装etcd集群 3.3.安装docker 3.4.安装master节点 3.5.安装node节点 3.6.部署集 ...

  2. Django model中的class Meta详解

    通过一个内嵌类 "class Meta" 给你的 model 定义元数据, 类似下面这样: class Foo(models.Model): bar = models.CharFi ...

  3. Python 学习 第十六篇:networkx

    networkx是Python的一个包,用于构建和操作复杂的图结构,提供分析图的算法.图是由顶点.边和可选的属性构成的数据结构,顶点表示数据,边是由两个顶点唯一确定的,表示两个顶点之间的关系.顶点和边 ...

  4. 性能调优8:分组聚合 - group by

    聚合实际上对数据做分组统计,SQL Server使用两种操作符来实现聚合,流聚合(Stream Aggregation)和哈希聚合(Hash aggration).流聚合是非阻塞性的,具有流的特性,流 ...

  5. 朱晔和你聊Spring系列S1E5:Spring WebFlux小探

    阅读PDF版本 本文会来做一些应用对比Spring MVC和Spring WebFlux,观察线程模型的区别,然后做一下简单的压力测试. 创建一个传统的Spring MVC应用 先来创建一个新的web ...

  6. 【JS复习笔记】03 继承(从ES5到ES6)

    前言 很久以前学习<Javascript语言精粹>时,写过一个关于js的系列学习笔记. 最近又跟别人讲什么原型和继承什么的,发现这些记忆有些模糊了,然后回头看自己这篇文章,觉得几年前的学习 ...

  7. python第一章:简介与安装--小白博客

    Python简介 Python是一种计算机程序设计语言.是一种动态的.面向对象的脚本语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的.大型项 ...

  8. SQLServer 存储过程+定时任务发邮件

    SQLServer 代理发邮件需要开启SQL Server 代理服务器,然后,在[管理]-[数据库邮件]中,右键点击配置数据库邮件. 我用的是腾讯的企业邮箱,个人的163邮箱略微不同.下图是相关邮件的 ...

  9. Python-Urllib库详解

    官方文档地址:https://docs.python.org/3/library/urllib.html 什么是Urllib: Urllib是python内置的HTTP请求库: urllib.requ ...

  10. 通过this()调用有参构造方法

    使用原因:在通过无参构造方法实例化对象时,如果有属性可以设置默认值,可通过在无参构造方法中使用this()调用有参构造方法实现. this()需要写在无参构造方法的第一行! 例子:在没有给出小猫的名字 ...