Codeforces_round297_B.Pasha and String

18 篇文章 0 订阅
5 篇文章 0 订阅

英文原题

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 spentm days performing the following transformations on his string — each day he chose integerai andreversed a piece of string (a segment) from positionai to position|s| - ai + 1. It is guaranteed that2·ai ≤ |s|.

You face the following task: determine what Pasha's string will look like afterm days.

Input

The first line of the input contains Pasha's strings of length from 2 to2·105 characters, 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 elementsai (1 ≤ ai;2·ai ≤ |s|) — the position from which Pasha started transforming the string on thei-th day.

Output

In the first line of the output print what Pasha's strings will look like after m days.

样例

Input

abcdef
1
2

Output

aedcbf

Input

vwxyz
2
2 2

Output

vwxyz

Input

abcdef
3
1 2 3

Output

fbdcea


        题意不是很好理解,不知道他想干嘛,分析了一下样例才明白,就是给你一个串,里面字符标号从1到n,然后他每次给你的数字ai意味着从标号ai到n-ai+1这一段翻转一下,胫骨多次操作以后问你最后的字符串。

这题显然要知道最后每个字符经历了几次翻转,由于每次翻转某一个字符翻到的位置是一定的就是它关于字符串中点对称的地方,所以我们只关心最终翻转次数的奇偶性,奇数则好对称位置,偶数则在原位。

不过记录每个字符的翻转次数还是比较困难的,这是区间操作,每一次操作从ai到n-ai+1里的所有翻转记录都加1,这里要用到树状数组的区间操作。

核心代码:

int arr[MAXN]={0};
inline int sum(int x){int res=0;while(x)res+=arr[x],x-=lowbit(x);return res;}
inline void add(int x,int n){while(x<MAXN)arr[x]+=n,x+=lowbit(x);}
inline int update(int x,int y,int n){add(x,n);add(y+1,-n);}

这里arr[]数组存放arr[x]表示该元素与左边元素的差,这题错了一次是因为没注意数据范围是200000,开始只开了100005的就RE了。

 

代码:

#include <iostream>
#include<stdio.h>
using namespace std;

string str;
int m,a,n;
const int MAXN=200005;
int arr[MAXN]={0};
int lowbit(int x)
{
    return x&(-x);
}

inline int sum(int x){int res=0;while(x)res+=arr[x],x-=lowbit(x);return res;}
inline void add(int x,int n){while(x<MAXN)arr[x]+=n,x+=lowbit(x);}
inline int update(int x,int y,int n){add(x,n);add(y+1,-n);}


int main()
{
    cin>>str;
    scanf("%d",&m);
    n=str.length();
    for(int i=0;i<m;i++)
    {
        scanf("%d",&a);
        update(a,n+1-a,1);
    }
    for(int i=1;i<=n;i++)
    {
        if(sum(i)%2==0)
        {
            printf("%c",str[i-1]);
        }else
        {
            printf("%c",str[n-i]);
        }
    }

    //cout << "Hello world!" << endl;
    return 0;
}


 

 


 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Educational Codeforces Round 146 (Rated for Div. 2)比赛中,有关于一个节点数量为n的问题。根据引用的结论,无论节点数量是多少,都可以将其分成若干个大小为2或3的区间使其错排,从而减少花费。根据引用的推导,我们可以通过组合数和差量来表示剩余的花费。而引用进一步推广了这个结论,可以使得任意长度的一段错排花费代价为边权和的两倍,并且通过贪心算法使得更多的边不被使用。以此来解决与节点数量相关的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Educational Codeforces Round 146 (Rated for Div. 2)(B,E详解)](https://blog.csdn.net/TT6899911/article/details/130044099)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Educational Codeforces Round 83 (Rated for Div. 2) D](https://download.csdn.net/download/weixin_38562130/14878888)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值