Dynamic Programming21 sections · 916 units
Open in Course

Bit Problem - Query Analysis

Subset relationships

Let's decode what each query asks as subsets:

1.1. xy=xx \mid y = x means every bit of yy is also in xx. So yy is a subset of xx. Count subsets of xx in the array.

2.2. xy=xx \land y = x means every bit of xx is also in yy. So xx is a subset of yy, meaning yy is a superset of xx. Count supersets of xx.

3.3. xy0x \land y \neq 0 means xx and yy share at least one bit. The complement: xy=0x \land y = 0 means yy is a subset of x\sim x (the bitwise complement). So count nn minus subsets of x\sim x.