Questions tagged [range-query]

8 questions
7
votes
2 answers

Queries to count points lying on arbitrary line

Suppose we have $N$ points on $XY$ plane, ie. $(x, y)$ and $x, y \in Z$ and multiple queries where each query is of the form $y = mx + c$ and $m, c \in Z$. Is it possible to count number of points that lie on the given line more efficiently than…
4
votes
1 answer

Segment trees with insertion/deletion

I have a range-query problem to solve. This problem requires not only range queries and update, but also insert or delete an element of the array. There is a series of operations that must be done in the order that they appear in the input. The…
matheuscscp
  • 345
  • 1
  • 4
  • 12
1
vote
1 answer

A data structure for range minimum queries

Here is a data structure question in the comparison model that I can't answer. I have an array $A$ of $n$ elements. I work in the comparison model, meaning that the elements can only be compared with each other. I would like to create a data…
1
vote
2 answers

Is there a data structure for lazy-loading time-series data?

I am writing a UI that needs to display a chat log, similar to Slack and Discord. In addition to being able to scroll and lazy-fetch additional pages in either direction, I need to be able to jump to a specific point in time and fetch the message…
0
votes
1 answer

Efficient merging of overlapping ranges with values preserving sum

Given a list of ranges each with an associated value, the metric at a point is the sum of the values of all overlapping ranges. The goal is to produce a list of non-overlapping ranges that preserve this metric. Currently, my algorithm is O(n^2) (I'm…
O'Schell
  • 1
  • 2
0
votes
1 answer

Can Merge Sort Tree find sum of K-th largest elements, in range [l, r] if the elements are not unique?

See below code: vector temp; for (int i = l; i <= r; ++i) { temp.push_back(holes[i]); } sort(temp.rbegin(), temp.rend()); long long needed_H2 = 0; for (int i = K; i < temp.size(); ++i) { needed_H2 += temp[i]; } Basically, it…
0
votes
0 answers

Zero sequence query in boolean array

I have a large array of bits of length $N$. The query $f(k, m)$ means "find $kth$ zero in the array and the next $m-1$ zeros after it", $k \in [0, N-1], m \ll N$ Currently I use a segment tree over the bit array and my approaches were: use kth zero…
Andrey Godyaev
  • 297
  • 1
  • 9
0
votes
0 answers

Sparse Table Memory Space Complexity

If we have input of size $N=13$, which represents array that has 13 element. We need in general $O(N\log{N})$ memory to store all intervals. We see that number of intervals we need in terms of power of $2^p$ is 3, so intervals is $p=3$. Problem: I…
Avv
  • 523
  • 4
  • 18