The overlap trick works for idempotent operations: f(a,a)=a.
Idempotent:
- min: min(a,a)=a ✓
- max: max(a,a)=a ✓
- gcd: gcd(a,a)=a ✓
- Bitwise AND: a∧a=a ✓
- Bitwise OR: a∨a=a ✓
NOT idempotent:
- Sum: a+a=2a=a ✗
- Product: a⋅a=a2=a ✗
- XOR: a⊕a=0=a ✗
- Count: overlapping counts twice ✗ For non-idempotent operations, you can still use Sparse Table, but queries become O(logn) because you must use non-overlapping ranges. Idempotent query: O(1). Non-idempotent query: O(logn). Space: O(nlogn).