The naive solution looks like this: For each query , loop from to and sum the elements. Simple and correct, but slow. If and , you're doing up to operations. Most judges give you about operations per second.
Your code would take 100 seconds. Time limit is usually 1-2 seconds. The problem isn't it's correctness. It's the repeated work. Every query recomputes sums from scratch. What if you precomputed something useful?