Bricks start with color equal to their index and colorfulness 0; range paint operations add the absolute color change to each brick, and queries ask for the total colorfulness over a range.
Hard8Segment treeImplementationMathDynamic programmingNo attempts yetTime limit2sMemory limit512 MB