codeforces525B
Pasha and String
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
abcdef
1
2
aedcbf
vwxyz
2
2 2
vwxyz
abcdef
3
1 2 3
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的更多相关文章
随机推荐
- 环境部署(一):Linux下安装JDK
自动化测试的主要目的是为了执行回归测试.当然,为了模拟真实的用户操作,一般都是在UAT或者生产环境进行回归测试. 为了尽量避免内网和外网解析对测试结果的影响,将自动化测试服务部署在外网的服务器是比较好 ...
- PIL、Pillow安装使用方法
PIL(Python Imaging Library)是Python常用的图像处理库,而Pillow是PIL的一个友好Fork,提供了了广泛的文件格式支持,强大的图像处理能力,主要包括图像储存.图像显 ...
- Scala--模式匹配和样例类
模式匹配应用场景:switch语句,类型查询,析构,样例类 一.更好的switch val ch :Char = '+' val sign = ch match{ case '+' => 1 c ...
- BZOJ3561 DZY Loves Math VI 莫比乌斯反演
传送门 看到\(gcd\)相关先推式子(默认\(N \leq M\)): \(\begin{align*} \sum\limits_{i=1}^N \sum\limits_{j=1}^M (lcm(i ...
- Java学习之路- SQL注入
用户名: __________ 密码:——————— 假如没有使用预处理的Statement 对象 拼接字符串查数据库的话,易收到sql注入攻击: 例如说 : mysql 中 #代表的是单行注释 ...
- 你不知道的腾讯社招面试经验(已offer)
# 你不知道的腾讯社招面试经验(已offer) ## 背景 最近一段时间换工作,成功获得了腾讯的offer.在这里有点经验跟大家分享,我觉得,比起具体的面试题,有些东西更加重要,你知道这些东西,再去准 ...
- 体验usually.js的管道函数——pipe函数
体验usually.js的管道函数——pipe函数 usually.js 是一个面向现代 Web 开发的 JavaScript 函数库,基于 ES6 开发.最新版本2.4.1,最新版本usually. ...
- 解决React通过ajax加载数据更新页面不加判断会报错的问题
通过AJAX加载数据是一个很普遍的场景.在React组件中如何通过AJAX请求来加载数据呢?首先,AJAX请求的源URL应该通过props传入:其次,最好在componentDidMount函数中加载 ...
- UVA 10820 欧拉函数模板题
这道题就是一道简单的欧拉函数模板题,需要注意的是,当(1,1)时只有一个,其他的都有一对.应该对欧拉函数做预处理,显然不会超时. #include<iostream> #include&l ...
- Linux下php安装redis扩展(redis已经安装)
1. 下载需要的php操作redis的扩展包 (1).切换到 cd /usr/local/src (2). wget https://github.com/nicolasff/phpredis ...