問題一覧 > 通常問題

No.789 Range Sum

レベル : / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 128 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 197
作問者 : horiesiniti / テスター : 37zigen
お気に入りにしたユーザー ProblemId : 2183 / 自分の提出
問題文最終更新日: 2020-01-23 03:16:19
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 205 (順位表) の他の問題:

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.

Query 0

$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もしくは右上の雲マークをクリックしてアカウントを作成してください。