HDU 原题地址


In a galaxy far, far away, there are two integer sequence a and b of length n.
b is a static permutation of 1 to n. Initially a is filled with zeroes.
There are two kind of operations:
1. add l r: add one for $a_l,a_{l+1}…a_r$
2. query l r: query $\sum_{i=l}^r \lfloor a_i / b_i \rfloor$


There are multiple test cases, please read till the end of input file.
For each test case, in the first line, two integers n,q, representing the length of a,b and the number of queries.
In the second line, n integers separated by spaces, representing permutation b.
In the following q lines, each line is either in the form ‘add l r’ or ‘query l r’, representing an operation.
$1≤n,q≤100000$, $1≤l≤r≤n$, there’re no more than 5 test cases.



线段树维护区间内最大的 $a$,最小的 $b$,懒惰标记以及所求的答案 $sum$。区间更新的时候如果 $\max a > \min b$ 就一直暴力更新到 $sum$ 更改的点上,然后令 $\min b = \min b + b_i$。