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. mongo固定集合

    固定集合:事先创建,大小固定 类型于环形队列,空间不足队列头文件被替换 不能手动删除文档,只能自动替换 db.ceateCollection("COLLECTION_NAME",{ ...

  2. Java关键字(三)——static

    我们说Java是一种面向对象编程的语言,而对象是把数据及对数据的操作方法放在一起,作为一个相互依存的整体,对同类对象抽象出其共性,便是Java中的类,我们可以用类描述世间万物,也可以说万物皆对象.但是 ...

  3. ML.NET 示例:推荐之矩阵分解

    写在前面 准备近期将微软的machinelearning-samples翻译成中文,水平有限,如有错漏,请大家多多指正. 如果有朋友对此感兴趣,可以加入我:https://github.com/fei ...

  4. 图解Redis之数据结构篇——链表

    前言     Redis链表为双向无环链表!     图解Redis之数据结构篇--简单动态字符串SDS提到Redis使用了简单动态字符串,链表,字典(散列表),跳跃表,整数集合,压缩列表这些数据结构 ...

  5. item 24: 区分右值引用和universal引用

    本文翻译自<effective modern C++>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 博客已经迁移到这里啦 古人曾说事情的真相会让你觉得很自在,但是在适当的情 ...

  6. flink1.7自定义source实现

    flink读取source data 数据的来源是flink程序从中读取输入的地方.我们可以使用StreamExecutionEnvironment.addSource(sourceFunction) ...

  7. H5 55-行高

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. PyCharm Debug 调试

    断点(breakpoint),表示标记一行的位置,当程序运行到该行代码的时候,会将程序暂时暂停,以便对该行代码进行分析. 编辑python脚本,debug.py def hello(): return ...

  9. Linux安装Apache常见报错(一)

    启动Apache提示报错:Could not reliably determine the server's fully qualified domain name, using localhost, ...

  10. vue echarts 动态数据

    安装echarts依赖 npm install echarts -S 或者使用国内的淘宝镜像: 安装 npm install -g cnpm --registry=https://registry.n ...