Problem10278--CF EDU - Segment Tree P1 - Step 4 - C. Number of Inversions on Segment

10278: CF EDU - Segment Tree P1 - Step 4 - C. Number of Inversions on Segment

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

Given an array $a$, consisting of small integers $(1≤a_i≤40)$. You need to build a data structure that processes two types of queries:

  1. find the number of inversions on a segment,
  2. change the element of the array.

Input

The first line contains two integers $n,q$, the length of the array and the number of queries, respectively $(1≤n,q≤10^5)$.

The second line contains $n$ numbers $a_1, ..., a_n$, where $a_i$ is the initial state of the array $(1≤a_i≤40)$.

The following $q$ lines describe the queries. Each of these lines has the format "type{_i} $x_i$ $y_i$".

If type$_i=1$, then in the $i$-th query you need to find the number of inversions on a segment from $x_i$ to $y_i$, inclusive (in this case $1≤x_i≤y_i≤n$).

If type$_i=2$, then the element with the index $x_i$ is set to $y_i$ (in this case $1≤x_i≤n,\ 1≤y_i≤40$).

Output

For each request of type 1 print the answer to this request on a separate line.

Sample 1 Input

7 6
1 2 3 6 5 4 19
1 1 3
1 2 5
1 2 4
2 2 8
1 1 6
1 1 3

Sample 1 Output

0
1
0
7
1

HINT

CF EDU.

Source/Category