Enemy is weak
HardRating 1900CodeforcesSegment Tree & Fenwick Tree
Approach hintTry it first, then revealHide
Treat each element as the middle of a triplet. Multiply the number of larger elements to its left by the number of smaller elements to its right, both counted with Fenwick trees over compressed values.