Under construction

Still being built. Things may change

Dipper and the Machine

Time limit2sMemory limit1024 MB

Summary
Given range-append operations on n strings, answer substring queries on the accumulated string of a single slot.
Level

Hard8 of 10

Topics
Segment tree, Binary search, Implementation
Solved
No attempts yet

Problem

Dipper found a strange machine in the attic today. The machine has nn slots numbered from 1 to nn, placed in a row. Each slot holds a string. At the start, every slot holds an empty string. Given ll, rr, and ss, the machine appends the string ss to the end of every string in slots ll through rr.

Dipper bet Mabel that she cannot model the machine. Dipper issues commands, and Mabel repeats each one in parallel. To check that Mabel copies the machine's behavior exactly, Dipper sometimes asks: what is the substring from position xx to position yy of the string in slot ii? Mabel wants a program that simulates this process. Help her.

Input

The first line contains two positive integers nn and mm, the number of slots and the number of Dipper's commands (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 1≤m≤2⋅1051 \le m \le 2 \cdot 10^5).

Each of the next mm lines contains one command, which has one of two types:

  • 1 ll rr ss: append the non-empty string ss to the end of every string in slots ll through rr inclusive (1≤l≤r≤n1 \le l \le r \le n). The string ss consists of lowercase Latin letters.
  • 2 ii xx yy: find the substring from xx to yy inclusive of the string in slot ii (1≤i≤n1 \le i \le n; 1≤x≤y1 \le x \le y). The length of the string in slot ii is guaranteed to be at least yy.

The total length of strings in type 1 commands does not exceed 10610^6. The total length of substrings requested by type 2 commands does not exceed 10610^6.

Output

For each command of type 2, print the answer on a separate line.

Examples2

  1. Example 1

    Input
    4 4
    1 2 2 two
    1 2 3 aa
    2 3 1 1
    2 2 1 4
    
    Expected output
    a
    twoa
    
  2. Example 2

    Input
    3 6
    1 1 2 ab
    1 2 3 cd
    2 2 2 4
    2 3 1 2
    1 1 3 xyzu
    2 1 2 5
    
    Expected output
    bcd
    cd
    bxyz