Dynamic Programming21 sections · 916 units
Open in Course

Codeforces 869B Kuriyama Mirai's Stones - Problem Statement

Two prefix arrays

This is Kuriyama Mirai's Stones from Codeforces. You have an array of nn stones with weights. Queries come in two types: Type 1: Sum of stones from ll to rr in the original array. Type 2: Sum of stones from ll to rr if the array were sorted.

You need to answer both types quickly. Think about it: how many prefix arrays do you need? Build 22 prefix arrays: one on the original, one on the sorted version.