-
if we look at [li,ri] as subsegments for each i, notice that they are disjoint
-
treat each interval as a seperate test case
-
the modifications x x x and $n−x+1 $ are equivalent
-
the modifications are symmetrical with respect to the middle of the string.
-
if a modification “touches” index i it also touches index n−i+1 , and also because of the symmetry, i will always be swapped with n−i+1 , and no other index.
批注:可以理解为,一旦索引为 i 的位置需要进行 reverse,它一定是和索引为 n-i+1 的元素进行交换。
-
the order of modifications doesn’t matter
-
given index i , all modifications such that x≤i affect this index
批注:这里的 affect 和上文的 touch 是一个意思
// Problem: D. Reverse Madness
// Contest: Codeforces - Codeforces Round 900 (Div. 3)
// URL: https://codeforces.com/contest/1878/problem/D
// Memory Limit: 256 MB
// Time Limit: 1000 ms
#include<iostream>
#include<algorithm>
#include<cstring> // memset
#include<string>
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N = 200010;
int n, k;
string s;
int l[N], r[N];
int q;
int x[N];
int cnt[N];
int main(void) {
int t;
cin >> t;
while (t -- ) {
memset(cnt, 0, sizeof cnt);
cin >> n >> k;
cin >> s;
for (int i = 0; i < k; i ++ ) {cin >> l[i]; l[i] -- ;}
for (int i = 0; i < k; i ++ ) {cin >> r[i]; r[i] -- ;}
cin >> q;
for (int i = 0; i < q; i ++ ) {cin >> x[i]; x[i] -- ; cnt[x[i]] ++ ;}
string res = "";
for (int i = 0; i < k; i ++ ) {
int sum = 0;
string son = s.substr(l[i], r[i]-l[i]+1);
for (int j = l[i]; j <= (l[i]+r[i])/2; j ++ ) {
sum += (cnt[j] + cnt[(l[i]+r[i]) - j]);
if (sum&1) {
swap(son[j-l[i]], son[r[i]-j]); // 子串和母串存在一个偏移 l[i]
}
}
res += son;
}
cout << res << endl;
}
return 0;
}