Upperbound - MarisaOJ: Marisa Online Judge

Upperbound

Time limit: 1500 ms
Memory limit: 256 MB
Given an array $A$ of $n$ elements, there are $q$ queries, each falling into one of two types: - `1 i x`: Assign the value $x$ to $A_i$. - `2 l r x`: Count the number of pairs $(i, j)$ such that $l \le i \le j \le r$ and the maximum value in the subarray $A_{i...j}$ does not exceed $x$. Answer the queries of type $2$. ### Input - The first line contains two integers $n, q$. - The second line contains $n$ integers $A_i$. - The next $q$ lines each contain a query in the specified format. ### Output - Print an integer as the answer for each query of type $2$. ### Constraints - $1 \le n,q \le 10^5$. - $1 \le A_i,x \le 10^9$. - $1 \le l \le r \le n$. ### Example Input: ``` 6 6 1 1 4 5 1 4 1 1 4 2 1 4 2 2 1 1 4 2 1 5 4 1 5 4 2 3 3 3 ``` Output: ``` 1 1 7 0 ```