Permutations strike back#2956

Permutations strike back

2 seconds
256 megabytes
Medium

Vasya initially wrote all the numbers from to on a board in a certain order, using each number exactly once. Occasionally, he erases a number and replaces it with another. The total number of numbers on the board is quite large, making it difficult for Vasya to view them all at once. To keep track of the sequence, he wrote a program that can, at any moment, answer the following question: How many numbers in positions from to (inclusive) have values in the range from to (inclusive)?

Do the same.

Input

The first line contains two integers: 1 \leq N \leq 100000 — the number of numbers Vasya initially wrote, and 1 \leq M \leq 100000 — the total number of queries and changes Vasya makes. The second line contains numbers, representing the sequence Vasya wrote. The following lines describe the queries. Each change request starts with the word SET and is in the format SET a b (1 \leq a \leq N, 1 \leq b \leq N), indicating that Vasya replaced the number at position with the number . Each query starts with the word GET and is in the format GET x y k l (1 \leq x \leq y \leq N, 1 \leq k \leq l \leq N).

Output

For each of Vasya's queries, output a single integer — the answer to the query.

Examples

Example 1

Loading
Loading