Question: I have several weather servers uploading reports to a central server with separate pages for each station's report showing gauges. The cycle on the uploads is at H+00 and H+30. I need the pages to auto refresh at H+03 and H+33 (24x7x365) to insure the page has current information.

I have tried several suggested JS solutions for auto refreshing pages particularly the Auto Refresh at the top of every hour discussion, but I can't get it quite right. I would appreciate any suggestions or code examples.

Answer: 
This is a very typical style problem in for segment trees, binary indexed trees, interval trees. 

There are two operations that you have to carry out on an array `arr`. 

You have two operations on an array `arr`:  

1. **Range update**: `Add(a, b): for(int i = a; i <= b; ++i) arr[i]++`  

2. **Point query** : `Query(x): return arr[x]` 

Alternately, you could formulate your problem slightly cleverly.  

1. **Point Update**: `Add(a, b): arr[a]++; arr[b+1]--;`  

2. **Range Query**: `Query(x): return sum(arr[0], arr[1] ..... arr[x]);`

In each of the cases above, you have one O(n) operation and one O(1) operation. 

For the second case, the query is essentially a prefix sum calculation. Binary Indexed Trees are especially efficient at this task.

[Tutorial for Binary Indexed Trees](https://www.hackerearth.com/practice/data-structures/advanced-data-structures/fenwick-binary-indexed-trees/tutorial/)

**IMPORTANT IDEA: ARRAY COMPRESSION**

You did mention that the vector size is about `10^6`, so there is a chance that you may not be able to create an array that big. If you are able to create a set that consists of all the `a`s and `b`s and `x`s beforehand, then you can translate them into numbers from `1` to `size of set`. 

**SUPER CLEVER IDEA: MO's ALGORITHM**

This is only allowed if you are allowed to solve the problem offline. What that means is that you can take all the query points `x` as input, solve them in any order as you like and store the solution, and then print the solution in the correct order. 

Please mention if this is your situation, and only then will I elaborate further on this. But Binary Indexed Trees are going to be more efficient than Mo's algorithm.

**EDIT:**

Because your interval values are of type `double`, you must convert them to integers before you use my solution. Let me give an example, 

`Intervals = (1.1 to 1.9), (1.4 to 2.1)
Query Points = 1.5, 2.0`

Here all the points that are of interest are not all the possible doubles, but just the above numbers `= {1.1, 1.4, 1.5, 1.9, 2.0, 2.1}` 

If we map them into positive integers:

```
1.1 --> 1
1.4 --> 2
1.5 --> 3
1.9 --> 4
2.0 --> 5
2.1 --> 6

```

Then you could use segment trees/binary indexed trees.
For each pair a,b you can decompose so that a=+1 and b=-1 for the number of ranges valid for a particular value. Then in becomes a simple O(log n) lookup to see how many ranges encompass the search value.