CF1878D.Reverse Madness

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string ss of length nn , containing lowercase Latin letters.

Next you will be given a positive integer kk and two arrays, ll and rr of length kk .

It is guaranteed that the following conditions hold for these 2 arrays:

  • l1=1l_1 = 1 ;
  • rk=nr_k = n ;
  • liril_i \le r_i , for each positive integer ii such that 1ik1 \le i \le k ;
  • li=ri1+1l_i = r_{i-1}+1 , for each positive integer ii such that 2ik2 \le i \le k ;

Now you will be given a positive integer qq which represents the number of modifications you need to do on ss .

Each modification is defined with one positive integer xx :

  • Find an index ii such that lixril_i \le x \le r_i (notice that such ii is unique).
  • Let a=min(x,ri+lix)a=\min(x, r_i+l_i-x) and let b=max(x,ri+lix)b=\max(x, r_i+l_i-x) .
  • Reverse the substring of ss from index aa to index bb .

Reversing the substring [a,b][a, b] of a string ss means to make ss equal to s1,s2,,sa1, sb,sb1,,sa+1,sa, sb+1,sb+2,,sn1,sns_1, s_2, \dots, s_{a-1},\ s_b, s_{b-1}, \dots, s_{a+1}, s_a,\ s_{b+1}, s_{b+2}, \dots, s_{n-1}, s_n .

Print ss after the last modification is finished.

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers nn and kk ( 1kn21051 \le k \le n \le 2\cdot 10^5 ) — the length of the string ss , and the length of arrays ll and rr .

The second line of each test case contains the string ss ( $ |s| = n$ ) containing lowercase Latin letters — the initial string.

The third line of each test case contains kk positive integers l1,l2,,lkl_1, l_2, \dots, l_k ( 1lin1 \le l_i \le n ) — the array ll .

The fourth line of each test case contains kk positive integers r1,r2,,rkr_1, r_2, \dots, r_k ( 1rin1 \le r_i \le n ) — the array rr .

The fifth line of each test case contains a positive integer qq ( $1 \le q \le 2 \cdot 10^5 $ ) — the number of modifications you need to do to ss .

The sixth line of each test case contains qq positive integers x1,x2,,xqx_1, x_2, \dots, x_q ( 1xin1\le x_i \le n ) — the description of the modifications.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot10^5 .

It is guaranteed that the sum of qq over all test cases does not exceed 21052\cdot10^5 .

It is guaranteed that the conditions in the statement hold for the arrays ll and rr .

输出格式

For each test case, in a new line, output the string ss after the last modification is done.

输入输出样例

  • 输入#1

    5
    4 2
    abcd
    1 3
    2 4
    2
    1 3
    5 3
    abcde
    1 2 3
    1 2 5
    3
    1 2 3
    3 1
    gaf
    1
    3
    2
    2 2
    10 1
    aghcdegdij
    1
    10
    5
    1 2 3 4 2
    1 1
    a
    1
    1
    1
    1

    输出#1

    badc
    abedc
    gaf
    jihgedcdga
    a

说明/提示

In the first test case:

The initial string is "abcd". In the first modification, we have x=1x=1 . Since l1=1xr1=2l_1=1\leq x \leq r_1=2 , we find the index i=1i = 1 . We reverse the substring from index x=1x=1 to l1+r1x=1+21=2l_1+r_1-x=1+2-1=2 . After this modification, our string is "bacd".

In the second modification (and the last modification), we have x=3x=3 . Since l2=3xr2=4l_2=3\leq x \leq r_2=4 , we find the index i=2i = 2 . We reverse the substring from index x=3x=3 to l2+r2x=3+43=4l_2+r_2-x=3+4-3=4 . After this modification, our string is "badc".

In the second test case:

The initial string is "abcde". In the first modification, we have x=1x=1 . Since l1=1xr1=1l_1=1\leq x \leq r_1=1 , we find the index i=1i = 1 . We reverse the substring from index x=1x=1 to l1+r1x=1+11=1l_1+r_1-x=1+1-1=1 . After this modification, our string hasn't changed ("abcde").

In the second modification, we have x=2x=2 . Since l2=2xr2=2l_2=2\leq x \leq r_2=2 , we find the index i=2i = 2 . We reverse the substring from index x=2x=2 to l2+r2x=2+22=2l_2+r_2-x=2+2-2=2 . After this modification, our string hasn't changed ("abcde").

In the third modification (and the last modification), we have x=3x=3 . Since l3=3xr3=5l_3=3\leq x \leq r_3=5 , we find the index i=3i = 3 . We reverse the substring from index x=3x=3 to l3+r3x=3+53=5l_3+r_3-x=3+5-3=5 . After this modification, our string is "abedc".

首页