Problems > Count Negatives in a Range > Editorial

Count Negatives in a Range — Solution & Editorial

Back to the Problem

Precompute a prefix array of negative-indicator counts; each query combines two prefix values (pre[R] − pre[L−1]).

Complexity: O(N + Q)