No.789 Range Sum
タグ : / 解いたユーザー数 197
作問者 :
horiesiniti
/ テスター :
37zigen
Problem Statement
There is an array $a[0],a[1],\ldots,a[1,000,000,000]$, initially filled with $0$. Two kinds of queries are given; output the answer.
Query 0
$0\ x\ y$Given in this form, it increases the value of $a[x]$ by $y$.
Query 1
$1\ l\ r$Given in this form, it computes the sum of $a[l],a[l+1],\ldots,a[r]$ at that point in time.
Output the total of the values of all Query 1s on one line.
If this is hard to understand, please infer the meaning from the sample input.
Input
$n$ $q_1$ $\vdots$ $q_i$ $\vdots$ $q_n$
Prepare a variable ans in your solution code, set ans to the value $0$, and then start processing all queries.
All input values are integers.
The first line contains $n$ satisfying $2 \le n \le 100000$.
Then $n$ queries, that is, the following $n$ lines of queries, are given.
Each $q_i$ is either Query 0 or Query 1.
$0$ $x$ $y$
A line of the form $0$ $x$ $y$ increases the value of $a[x]$ by $y$.
Query 1
$1$ $l$ $r$
It computes the sum of $a[l],a[l+1],\ldots,a[r]$ and adds it to ans.
Of course, $x$, $l$, and $r$ are all natural numbers from $0$ to $10^9$.$0 \le l\le r \le 10^9$
$0 \le y \le 1000$
are satisfied. After processing the last query, output ans on one line.
Output
ans
Print a newline at the end.
Sample
Sample 1
Input
10 0 5 2 0 4 3 1 3 5 0 2 1 1 2 4 0 4 2 0 4 4 0 7 1 1 2 5 1 0 10
Output
34
The value of ans increases as $5,9,21,34$ with each Query 1, and $34$ is output after the last query finishes.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。