#P15620. [ICPC 2022 Jakarta R] Substring Sort

[ICPC 2022 Jakarta R] Substring Sort

题目描述

In this problem, all strings are one-based indexed. Let sis_i be the ithi^{th} character of a string ss. Let sl..rs_{l..r} be a substring of ss with the characters slsl+1srs_l s_{l+1} \cdots s_r.

You are given three strings each of length NN: AA, BB, and CC. You are asked to simulate QQ queries according to the given order.

For each query, you are given two integers ll and rr as parameters, and must perform the following procedures:

  1. Copy substrings Al..rA_{l..r}, Bl..rB_{l..r}, and Cl..rC_{l..r}. Let xx, yy and zz be the copied substrings.
  2. Sort [x,y,z][x, y, z] in lexicographical order. Let [x,y,z][x', y', z'] be the sorted results.
  3. Replace substring Al..rA_{l..r} with xx', substring Bl..rB_{l..r} with yy' and substring Cl..rC_{l..r} with zz' respectively.

Determine the value of AA, BB, and CC after all queries.

输入格式

Input begins with two integers NN QQ (1N1000001 \leq N \leq 100\,000; 1Q1000001 \leq Q \leq 100\,000) representing the length of the given strings and the number of queries. Each of the next 33 lines contains a string of length NN. The first, second, and third lines contain AA, BB, and CC respectively. The strings consist of lowercase characters. Each of the next QQ lines contains two integers ll rr (1lrN1 \leq l \leq r \leq N) representing the parameters of each query.

输出格式

The output consists of 33 lines. In each line, output the final value of AA, BB and CC after all queries in that order.

5 2
icpca
siaja
karta
2 4
1 5
iarta
kiaja
scpca
6 6
aabbcc
bcacab
cbcaba
1 1
2 2
3 3
4 4
5 5
6 6
aaaaaa
bbbbbb
cccccc
3 1
aba
aab
aac
1 3
aab
aac
aba

提示

Explanation for the sample input/output #1

In the first query, the value of xx, yy, and zz are cpc, iaj, art respectively. After sorting those strings, the value of xx', yy', and zz' becomes art, cpc, iaj. At the end of the first query, the value of AA, BB, and CC are iarta, scpca and kiaja.

During the second query, the value of xx, yy, and zz are iarta, scpca, kiaja respectively. After sorting those strings, the value of xx', yy', and zz' becomes iarta, scpca, kiaja. At the end of the second query, the value of AA, BB, and CC are iarta, kiaja and scpca.

Therefore the final value of AA, BB, CC are iarta, kiaja and scpca respectively.