F-fTime
limit:2000MS
Memory Limit:262144KB
64bit IO Format:%i64d &%i6 4u SubmitStatus
Description
Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string is numbered from 1 to | S| From left to right, where | S| Is the length of the given string.
Pasha didn ' t like its present very much so he decided to change it. After him birthday Pasha spent m days performing the following transformations on his String-each day he ch OSE integer ai and reversed a piece of string (a segment) from position a i to position | S| - ai + 1. It is guaranteed. 2 · Ai ≤| S|.
The following task:determine what Pasha ' s string would look like after m days.
Input
The first line of the input contains Pasha's string s of length from 2 to 2 10 5 characters, Consi Sting of lowercase Latin letters.
The second line contains a single integer m (1≤ m ≤105)-the number of days when Pasha C Hanged his string.
The third line contains m space-separated elements ai (1≤ a I; 2 · a I ≤| 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 would look like after m days.
Sample Input
Input
ABCdef
1
2
Output
Aedcbf
Input
Vwxyz
2
2 2
Output
Vwxyz
Input
ABCdef
3
1 2 3
Output
Fbdcea
Test instructions is a string that is said to be an inverted transform (from a[i] position to a[l-i+1], and a string to be asked.
It is easy to find that the more the characters in the inside (symmetrical, that is, the closer to the middle position), the more the number of exchanges.
We can sort the a[i] from small to large.
Then through the analysis found that the two adjacent a[i] into a group, do processing, if M is odd, and finally left A[m] is not grouped, to deal with A[m]
Notice in detail that the St array starts from st[0] ... Well, it's really inconvenient, and the ox says I am. After the array subscript or starting from 0 ... Mainly by the high school Oi Pascal's influence ... That array subscript casually.
Code:
#include <iostream>#include<algorithm>#include<cstring>#include<cmath>#include<cstdio>using namespacestd;intM,k,len;Const intn=2e5+7;intA[n];CharSt[n];intMain () {CIN>>St; scanf ("%d",&m); for(inti =1; I <= m; i++) scanf ("%d",&A[i]); Sort (a+1, a+m+1); K=1; Len=strlen (ST); while(k<=m) { for(intj = A[k]; J <= a[k+1]-1; J + +) Swap (St[j-1],st[len-J]); K= k +2; } if(M%2==1 ) for(inti = a[m]; I <= len/2; i++) Swap (St[i-1],st[len-i]); cout<<st<<Endl; return 0;}
Hust New Game 20150407 F