Substring Sort
Time limit2sMemory limit1024 MB
Each query sorts the three substrings A[l..r], B[l..r], and C[l..r] and writes them back in sorted order. Print the final A, B, and C.
- Level
Hard8 of 10
- Topics
- String, Segment tree, String matching
- Solved
- No attempts yet
Problem
In this problem, all strings are indexed from 1. is the th character of string , and is the substring .
You are given three strings , , and , each of length . You must process queries in order. Each query gives two integers and , and you perform these steps:
- Copy the substrings , , and . Call the copies , , and .
- Sort in lexicographical order. Call the sorted result .
- Replace with , with , and with .
Find the final values of , , and after all queries.
Input
The first line has two integers and (, ). The next three lines contain the strings , , and , each of length , made of lowercase letters. Each of the next lines contains two integers and ().
Output
Print three lines with the final values of , , and , in that order.