Дан массив и q запросов. Каждый запрос это l, r, x на каждый запрос вам надо ответить количество чисел на отрезке l, r меньших чем x.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3773 |
3 | Radewoosh | 3646 |
4 | ecnerwala | 3624 |
5 | jqdai0815 | 3620 |
5 | Benq | 3620 |
7 | orzdevinwang | 3612 |
8 | Geothermal | 3569 |
8 | cnnfls_csy | 3569 |
10 | gyh20 | 3447 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | awoo | 161 |
2 | maomao90 | 160 |
3 | nor | 157 |
4 | atcoder_official | 156 |
4 | cry | 156 |
6 | -is-this-fft- | 155 |
7 | maroonrk | 154 |
8 | adamant | 153 |
9 | Um_nik | 151 |
10 | djm03178 | 146 |
Дан массив и q запросов. Каждый запрос это l, r, x на каждый запрос вам надо ответить количество чисел на отрезке l, r меньших чем x.
Название |
---|
Если запросы оффлайн, можно сделать сканлайн с фенвиком.
Если онлайн, то MergeSortTree.
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)