## maximise BITWISE AND find an integer in range [L,R]

Given an integer x
find y in range L<=y<=R so that x & y is maximum & is Bitwise AND where 0< L, R <10^12 I had tried to iterate and solve but it is resulting in TLE

## Why does a range query on a segment tree return at most \$\lceil \log_2{N} \rceil\$ nodes?

If an array $$A[1 \ldots N]$$ is represented using a segment tree having sets in each interval, why does a range query $$[L\ldots R]$$ returns at most $$\lceil \log_2{N} \rceil$$ sets (or disjoint intervals)?

To quote:

Find a disjoint coverage of the query range using the standard segment tree query procedure. We get $$O(\log n)$$ disjoint nodes, the union of whose multisets is exactly the multiset of values in the query range. Let’s call those multisets $$s_1, \dots, s_m$$ (with $$m \le \lceil \log_2 n \rceil$$).

I tried searching for a proof, but couldn’t find it on any site. Can anyone help me prove it?

## Matrix multiplication over range in \$O(n)\$

Let $$M$$ denote the time it takes to multiply 2 matrices, and $$Q$$ denote the number of queries.

Is it possible to create a data structure with $$O((n+Q)M)$$ pre-computation time, and can answer range matrix multiplication queries that satisfy $$l_{i-1}\le l_i$$ and $$r_{i-1}\le r_i$$ with an overall time complexity of $$O((n+Q)M)$$. I’ve been thinking a lot on how to manipulate 2 pointers to get the intended results, but haven’t come up with any approach yet. The matrices are not necessarily invertible.

## Can a Major Image illusion move outside of the range in which it was originally cast?

Major Image (relevant sections):

You create the image of an object, a creature, or some other visible phenomenon that is no larger than a 20.foot cube. The image appears at a spot that you can see within range and lasts for the duration.

As long as you are within range of the illusion, you can use your action to cause the image to move to any other spot within range. As the image changes location, you can alter its appearance so that its movements appear natural for the image. For example, if you create an image of a creature and move it, you can alter the image so that it appears to be walking.

At Higher Levels: When you cast this spell using a spell slot of 6th level or higher, the spell lasts until dispelled, without requiring your concentration.

I initially presumed this to mean you can create an illusion limited by the 20ft cube maximum size, and then the illusion can move within the original 120ft casting radius, with no option to leave it. But upon reading it again, it seems that if the caster is within range of the illusion, the character can command the illusion to move outside any initial range, and indeed can have the illusion follow the character around the map for miles. Is this correct?

## If the initial target of the Hex spell is reduced to 0 HP, can the curse be moved to an unseen target or one out of range?

To originally cast the spell hex, you must target “a creature you can see within range”. The spell says that if the target drops to 0 hit points before the spell ends, the caster can use a bonus action on a subsequent turn to move the curse to a new creature. However, it does not say that the new creature being cursed has to be seen or within range.

If the initial target of hex is reduced to 0 HP, can the curse be moved to an unseen target or one out of range?

Rules as Written, it seems possible to do so, but that seems a bit overpowered.

## Level Range of Dragon of Icespire Peak

I am planning to run a introductory campaign with the scenario ‘Dragon of Icespire Peak’, and I would like to estimate how long it will going to take. However, there is no where in the book written about the level range of this scenario, unless I have miss some phrases.

Can someone tell me what is the level range and how long the campaign would take assuming playing it once a week for about 4 to 5 hours each.

## How to convert a range of 0 – 1023 to 0 – 255? [closed]

Hi smart community,

I am stuck with a problem where I get an input somewhere between the range of 0 to 1023 and I want to give an output ranging between 0 to 255 as per the input value. How should I do it? Quick note that I don’t want to use any libraries only for my own satisfaction.

I do find kind of similar questions already answered but I would rather welcome an explained derivation to the formula you provide. Thanks very much 🙂

## Why do ranged weapons in D&D have two numbers to show their range e.g light crossbow 80/320?

You can use a ranged weapon from 5ft to it’s full range without there being a disadvantage and I know that the second number, in this case 320, is how far it can shoot, but what is the first number for? Are you at a disadvantage when you use the light crossbow cloaser than 80ft away from your target?

## Do spells with the Attack trait have a range increment?

From Core Rulebook, p. 279:

Range: Ranged and thrown weapons have a range increment. Attacks with these weapons work normally up to that distance. Attack rolls beyond a weapon’s range increment take a –2 penalty for each additional multiple of that increment between you and the target. Attacks beyond the sixth range increment are impossible.

For example, a shortbow takes no penalty against a target up to 60 feet away, a –2 penalty against a target beyond 60 feet but up to 120 feet away, and a –4 penalty against a target beyond 120 feet but up to 180 feet away, and so on, up to 360 feet.

What I am trying to figure out is if this also applies to spells which have the Attack trait and thus perform a ranged attack when cast against a target.

On one hand, Core Rulebook states on p. 304:

Targets: Some spells allow you to directly target a creature, an object, or something that fits a more specific category. The target must be within the spell’s range, and you must be able to see it (or otherwise perceive it with a precise sense) to target it normally.

On the other hand, it also states for Spell Attacks on p. 305:

Spell Attacks: Some spells require you to succeed at a spell attack roll to affect the target. This is usually because they require you to precisely aim a ray or otherwise make an accurate attack. A spell attack roll is compared to the target’s AC. Spell attack rolls benefit from any bonuses or penalties to attack rolls, including your multiple attack penalty, but not any special benefits or penalties that apply only to weapon or unarmed attacks.

So, if I cast for example Divine Lance (p. 331) which has the Attack Trait, a range of 30 feet and targets 1 creature, is the spell able to hit a target further than 30 feet from me but with the appropriate range increment penalty taken into account? Or is it completely ineffective for any target out of nominal range (30 feet for the aforementioned spell)?

## Does enlarging a character with a reach weapon affect his threat range?

In the PHB on page 147 about reach weapons:

Reach. This weapon adds 5 feet to your reach when you attack with it, as well as when determining your reach for opportunity attacks with it.

In the PHB on page 237 about the Enlarge/Reduce spell:

Enlarge: The target’s size doubles in all dimensions, and its weight is multiplied by eight. This growth increases its size by one category—from Medium to Large, for example. If there isn’t enough room for the target to double its size, the creature or object attains the maximum possible size in the space available. Until the spell ends, the target also has advantage on Strength checks and Strength saving throws. The target’s weapons also grow to match its new size. While these weapons are enlarged, the target’s attacks with them deal 1d4 extra damage.

Even if it’s not specifically stated in the rules and it might lead to making the spell that much powerful (especially with the Sentinel feat) I find it unreasonable to tell my players that an enlarged glaive doubles it’s dimensions but not it’s physical properties like reach.