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: 
In addition to the previous answer, here's a suggestion how to prepare the ranges to optimize the subsequent lookup. The idea boils down to precomputing the result for all significantly different input values, but being smart about when values don't differ significantly.

To illustrate what I mean, let's consider this sequence of ranges:

```
1, 3
1, 8
2, 4
2, 6

```

The prepared output structure then looks like this:

```
1, 2 -> 2
2, 3 -> 4
3, 4 -> 3
4, 6 -> 2
6, 8 -> 1

```

For any number in the range `1, 2`, there are two matching ranges in the initial sequence. For any number in the range `2, 3`, there are four matches, etc. Note that there are five ranges here now, because some of the input ranges partially overlapped. Since for every range here the end value is also the start value of the next range, the end value can be optimized out. The result then looks like a simple map:

```
1 -> 2
2 -> 4
3 -> 3
4 -> 2
6 -> 1
8 -> 0

```

Note here that the last range didn't have one following, so the explicit zero becomes necessary. For the values before the first, that is implied. In order to find the result for a value, just find the key that is less than or equal to that value. This is a simple O(log n) lookup.
Firstly, if you just did a simple scan over the pairs, you would have O(n) complexity! The O(n log n) comes from sorting and for a one-off operation this is just overhead. This might even be the best way to do it, if you don't reuse the results and even if you just perform a few queries, it might still be better than sorting. Make sure you allow yourself to switch out the algorithm.

Anyhow, let's consider that you need to make many queries. Then, one relatively obvious step to improve things is to not iterate step-by-step after sorting. Instead, you can do a binary search for the lower bound. Simply partition the sequence into halves. The lower bound can be found in either half, which you can determine by looking at the middle element between the partitions. Recurse until you found the first element that can not possibly contain the value you search, because its start value is already greater.

Concerning the other direction, things are not that easy. Just because you sorted the ranges by the start value doesn't imply that the end values are sorted, too. Also, ranges that match and ranges that don't can be mixed in the sequence, so here you will have to perform a linear scan.

Lastly, some notes:

* You could parallelize this algorithm using multithreading.
* Depending on your number of searches M in your outer loop, you could also switch the outer loop with the inner one. That means that for every pair of the input vector, you check each of the M search values whether they fall within the range. This might be better, in particular when the M searches fit into the CPU cache.