Substring Sort

시간 제한2초메모리 제한1024 MB

요약
A, B, C의 l..r 구간 부분 문자열 세 개를 사전순으로 정렬해 다시 배정하는 질의 Q개를 순서대로 처리한 뒤 최종 문자열을 출력한다.
난이도

어려움10점 중 8점

유형
문자열, 정렬, 세그먼트 트리, 구현
정답자
아직 제출이 없습니다

문제

In this problem, all strings are one-based indexed. Let s_is\_i be the iith character of a string ss. Let s_l..rs\_{l..r} be a substring of ss with the characters s_ls_l+1⋯s_rs\_ls\_{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 performs the following procedures:

  1. Copy substrings A_l..rA\_{l..r}, B_l..rB\_{l..r}, and C_l..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 A_l..rA\_{l..r} with x′x', substring B_l..rB\_{l..r} with y′y' and substring C_l..rC\_{l..r} with z′z' respectively.

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

입력

Input begins with two integers NN QQ (1≤N≤100,0001 ≤ N ≤ 100\\, 000; 1≤Q≤100,0001 ≤ Q ≤ 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 Q lines contains two integers ll rr (1≤l≤r≤N1 ≤ l ≤ r ≤ 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.

예제3

  1. 예제 1

    입력
    5 2
    icpca
    siaja
    karta
    2 4
    1 5
    
    예상 출력
    iarta
    kiaja
    scpca
    
  2. 예제 2

    입력
    6 6
    aabbcc
    bcacab
    cbcaba
    1 1
    2 2
    3 3
    4 4
    5 5
    6 6
    
    예상 출력
    aaaaaa
    bbbbbb
    cccccc
    
  3. 예제 3

    입력
    3 1
    aba
    aab
    aac
    1 3
    
    예상 출력
    aab
    aac
    aba