Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory. Now the poor princess is in trouble again and Mario needs to save his lover. We regard the road to the boss’s castle as a line (the length is n), on every integer point i there is a brick on height hi. Now the question is how many bricks in [L, R] Mario can hit if the maximal height he can jump is H. Input The first line follows an integer T, the number of test data. For each test data: The first line contains two integers n, m (1 <= n <=10^5, 1 <= m <= 10^5), n is the length of the road, m is the number of queries. Next line contains n integers, the height of each brick, the range is [0, 1000000000]. Next m lines, each line contains three integers L, R,H.( 0 <= L <= R < n 0 <= H <= 1000000000.) Output For each case, output "Case X: " (X is the case number starting from 1) followed by m lines, each line contains an integer. The ith integer is the number of bricks Mario can hit for the ith query. Sample Input 1 10 10 0 5 2 7 5 4 3 8 7 7 2 8 6 3 5 0 1 3 1 1 9 4 0 1 0 3 5 5 5 5 1 4 6 3 1 5 7 5 7 3 Sample Output Case 1: 4 0 0 3 1 2 0 1 5 1 求l到r中小于k的數字個數。 對于這種l到r的八九不離十是線段樹或者主席樹,根據題目而定。 這個題目就是利用主席樹,由于數據量比較大,所以需要離散化一下。關于離散化和不離散化對于主席樹的影響,離散化之后,我們在插入數據的時候,是根據數據在數組中的相對位置,就是lower_bound之后的數。但是不離散化,我們就可以直接按著權值插入數據。權值線段樹也是醬紫。我在做主席樹或者權值線段樹的時候,有時就分不清該是用位置還是權值,就很懵逼。感覺這樣判斷還是比較正確的,不對的話希望大佬可以指正。 代碼如下: