Given array A and Q queries. Each query is l, r, x for every query you need to calc number of elements that less than x.
# | User | Rating |
---|---|---|
1 | tourist | 3880 |
2 | jiangly | 3669 |
3 | ecnerwala | 3654 |
4 | Benq | 3627 |
5 | orzdevinwang | 3612 |
6 | Geothermal | 3569 |
6 | cnnfls_csy | 3569 |
8 | jqdai0815 | 3532 |
9 | Radewoosh | 3522 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | awoo | 161 |
1 | maomao90 | 161 |
3 | adamant | 156 |
4 | maroonrk | 153 |
5 | -is-this-fft- | 148 |
5 | atcoder_official | 148 |
5 | SecondThread | 148 |
8 | Petr | 147 |
9 | nor | 144 |
10 | TheScrasse | 142 |
Given array A and Q queries. Each query is l, r, x for every query you need to calc number of elements that less than x.
Name |
---|
I think you can create for example fenwick tree or segment tree of order statistic trees and then sum up orders of x in all order statistic trees in [l, r].
EDIT: Or simply a merge sort tree.
You can solve offline the queries. 1) sort the queries in nondecreasing order regarding x; 2) build an array V with 2 parameters: the value of A[i] and i, the position, then sort V regarding first value; 3) after these operations, keep 2 pointers: you will start i from the first value from V and start with j from the first element in Q (sorted); update the values in the binary indexed tree unless V[i].first_parameter will be >= the x from actual j query, then calculate with BIT the answer like this: sum of first r values in BIT — sum of first l-1 values in BIT, then print this value.
For offline:Sort the queries by x,then for each query,add the elements(weren't added before)less than x into the i-th position of a BIT.Then check the sum in interval l and r.Complexity is
.
For online:Discrete the array first.Then build a persistent segment tree.The i-th version contains the first i elements in the array.The difference between i and i-1 is the a[i]-th position is increased by 1.For a query,the answer is:the sum in [l,r] in the r-th tree minus the sum in [l,r] in the l-1-th tree.The Complexity is also
.
Some mistakes here...
For a query,the answer is:the sum in [l,r] in the r-th tree minus the sum in [l,r] in the l-1-th tree
it should be:
For a query,the answer is:the sum in [1,y] in the r-th tree minus the sum in [1,y] in the l-1-th tree(y is the number of elements strictly less than x in the whole array)