Groups
The contribution technique flips perspective: compute how much each element contributes to the total, then sum these contributions.
A monotonic stack is a stack that keeps its elements in increasing or decreasing order to answer range queries in linear time.