Range Sum

Time: 1.0 s     Memory: 1024 MB
  • An array of $N$ positive integers is given. Your task is to answer $Q$ queries of the form "what is the sum of the numbers in the interval$[l,r]$".

    Indata

    The first line of input contains two integers $N, Q$ ($1 \leq N \leq 3 \cdot 10^5$, $1 \leq Q \leq 10^5$).

    The next row contains $N$ positive integers $1 \leq A_i \leq 10^9$.

    Afterwards, $Q$ lines follow, each containing two integers $L_{i},R_{i}$ ($0 \leq L_{i} \leq R_{i} \leq N-1$), the interval for the $i$:th question.

    Utdata

    Output $Q$ rows, with the $i$:th one containing the answer to the $i$:th question.

    Poängsättning

    Your program will be tested on two subtask groups. To get points for a group, your program must correctly solve in test case in the group.

    Group

    Points

    Constrains

    $1$

    $50$

    $N,Q \leq 1000$

    $2$

    $50$

    No further constraints

    Sample Input 1 Sample Output 1
    5 4
    1 4 3 1 2
    0 3
    0 1
    2 3
    1 2
    
    9
    5
    4
    7
    
CCC lectures
You must log in to submit solutions to the problem.
{"contest_start_timestamp": 1681196400, "contest_duration": 54000, "contest_started": true, "contest_ended": true, "flexible_start_window_end_time": null, "only_virtual": false}