Candy Compress

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

요약
문자열에 삽입과 구간 삭제가 번갈아 일어날 때 각 삭제 연산에서 지워지는 문자들을 출력한다.
난이도

어려움10점 중 8점

유형
트리, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

You are developing a mobile game called Candy Compress. In this game, there are several colored candies lined up from left to right. There are 2626 possible colors. At any point in time, the player can choose to add a candy at any position or to remove a subset of neighboring candies to get points depending on the colors of the removed candies.

To develop the game, you need to implement the following data structure. Initially, the data structure loads a 11-indexed string of nn characters, which represents the colors of the initial candies. The string consists of only uppercase Latin characters (A–Z). After loading the string, there are qq operations that you need to support. Each operation is either one of the following:

  • Operation 1: Insert the uppercase Latin character cc to the string so that the character is in the ii-th position in the new string. In particular, i=1i = 1 means inserting character cc at the beginning of the string. It is guaranteed that 1≤i≤m+11 ≤ i ≤ m + 1, where mm is the length of the string just before this operation.
  • Operation 2: Remove the characters of the string from the ll-th to the rr-th position, inclusive. It is guaranteed that 1≤l≤r≤m1 ≤ l ≤ r ≤ m, where mm is the length of the string just before this operation.

For each Operation 2, your data structure needs to determine the characters that are removed, so that the game can calculate the number of points to be given to the player. In other words, you need to determine the content of the string from the ll-th position to the rr-th position just before the operation.

입력

The first line of input contains two integers nn and qq (1≤n≤300,0001 ≤ n ≤ 300\\, 000; 1≤q≤300,0001 ≤ q ≤ 300\\, 000). The second line contains a string consisting of nn uppercase Latin characters representing the initial string to be loaded by the data structure. Each of the next qq lines represents an operation with either one of the following formats:

  1. 1 cc ii represents an Operation 1. It is guaranteed that cc is an uppercase Latin character and 1≤i≤m+11 ≤ i ≤ m + 1, where mm is the length of the string just before this operation.
  2. 2 ll rr represents an Operation 2. It is guaranteed that 1≤l≤r≤m1 ≤ l ≤ r ≤ m where mm is the length of the string just before this operation.

The operations are given in the order they are to be performed. It is guaranteed that there is at least one Operation 2.

출력

For each Operation 2 in order, output one line containing the characters that are removed by the operation.

예제2

  1. 예제 1

    입력
    3 5
    XPA
    1 P 3
    1 P 5
    2 2 5
    1 Y 2
    2 1 2
    
    예상 출력
    PPAP
    XY
    
  2. 예제 2

    입력
    27 7
    ICPCASIAPACIFICCHAMPIONSHIP
    2 5 8
    2 5 11
    1 A 5
    1 P 6
    1 A 7
    1 C 8
    2 1 8
    
    예상 출력
    ASIA
    PACIFIC
    ICPCAPAC