Substring Sort
시간 제한2초메모리 제한1024 MB
A, B, C의 l..r 구간 부분 문자열 세 개를 사전순으로 정렬해 다시 배정하는 질의 Q개를 순서대로 처리한 뒤 최종 문자열을 출력한다.
문제
In this problem, all strings are one-based indexed. Let be the th character of a string . Let be a substring of with the characters .
You are given three strings each of length : , , and . You are asked to simulate queries according to the given order.
For each query, you are given two integers and as parameters, and must performs the following procedures:
- Copy substrings , , and . Let , and be the copied substrings.
- Sort in lexicographical order. Let be the sorted results.
- Replace substring with , substring with and substring with respectively.
Determine the value of , , and after all queries.
입력
Input begins with two integers (; ) representing the length of the given strings and the number of queries. Each of the next lines contains a string of length . The first, second, and third lines contain , , and respectively. The strings consist of lowercase characters. Each of the next Q lines contains two integers () representing the parameters of each query.
출력
The output consists of lines. In each line, output the final value of , and after all queries in that order.