Problem 2613 · Hard

Beautiful Pairs

Treat each index as a point and sweep left to right; two Fenwick trees find the nearest Manhattan partner below and above each point.

Open the interactive visualisation