Selecting array values

I have two arrays DIST(1:NCOF) and X(1:NX)

Let NCOF = 5 and NX = 15, with

DIST = [10 20 30 40 50] and
X = [ 30.3 40.4 50.3 60.6 70.4 80.5 90.3 100.7 110.4 120.7 130.6 140.5 150.5 160.2 170.4]

I want to create an array that puts a zero if DIST is outside the region in X, otherwise putting 1.

In this example I should get

RES =  [0 0 0 1 1]
Using DIST = [150 160 170 180 190] would give RES = [1 1 1 0 0]

The values in DIST will be consecutive and they will get out of range from only one side, either to the right or to the left side of DIST.
This can help to doing the check more efficiently, than checking every value.

So what are you trying to get at?

Trying to know which values in DIST are valid as the data I have are at X.

I do get that and it should be a fairly simple program unless you are trying to find a highly optimized solution.

It would be better to find a way not to loop through all values.

Are the two arrays sorted or do they need to be sorted...because if they need to be sorted then sorting is your solution otherwise yes it would be good not to have to loop throgh all the values.

---------- Post updated at 11:24 AM ---------- Previous update was at 11:21 AM ----------

One approach could be to find the midpoint of DIST and compare it to the end points of X and then move either left or right of the midpoint of DIST based on the result of the previous comparison.

Yes, both Dist and X are sorted