10278: CF EDU - Segment Tree P1 - Step 4 - C. Number of Inversions on Segment
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:
- find the number of inversions on a segment,
- 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
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