Under construction

Still being built. Things may change

Candy Compress

Time limit2sMemory limit1024 MB

Summary
Maintain a string under insertions of single characters and deletions of substrings, and report the substring removed by each deletion.
Level

Medium7 of 10

Topics
Implementation, Tree, Divide and conquer
Solved
No attempts yet

Problem

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 only of uppercase Latin characters (A to Z). After loading the string, there are qq operations to support:

  • Operation 1: Insert the uppercase Latin character cc into the string so that it is at the ii-th position in the new string. In particular, i=1i = 1 means inserting 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 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, the data structure must determine the characters that are removed, so the game can calculate the points to award. In other words, you must find the content of the string from the ll-th to the rr-th position just before the operation.

Input

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 of nn uppercase Latin characters, the initial string to be loaded. Each of the next qq lines is one of the following operations:

  1. 1 cc ii is 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 is 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 performed. There is at least one Operation 2.

Output

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

Examples2

  1. Example 1

    Input
    3 5
    XPA
    1 P 3
    1 P 5
    2 2 5
    1 Y 2
    2 1 2
    
    Expected output
    PPAP
    XY
    
  2. Example 2

    Input
    27 7
    ICPCASIAPACIFICCHAMPIONSHIP
    2 5 8
    2 5 11
    1 A 5
    1 P 6
    1 A 7
    1 C 8
    2 1 8
    
    Expected output
    ASIA
    PACIFIC
    ICPCAPAC