This is a huge class of problems and there are so many techniques for solving them, so really to learn them you just have to do a bunch of problems of that type. Here are a few ways to solve some problems of this form though: Cumulative sum arrays (pre-compute the sum of the first k elements for all k and store these in an array), Segment trees, Square root decomposition, Mo's algorithm
This is a huge class of problems and there are so many techniques for solving them, so really to learn them you just have to do a bunch of problems of that type. Here are a few ways to solve some problems of this form though: Cumulative sum arrays (pre-compute the sum of the first k elements for all k and store these in an array), Segment trees, Square root decomposition, Mo's algorithm