Files
luogu/P3374.md
T
hanyixuanten f94e8e3dcd
Check cpp / md pair / Check md headers (push) Successful in 3s
modified: P3374.cpp
2026-10-28 11:08:59 +00:00

63 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# P3374 【模板】树状数组 1
## 题目描述
如题,已知一个数列,你需要进行下面两种操作:
- 将某一个数加上 $x$;
- 求出某区间每一个数的和。
## 输入格式
第一行包含两个正整数 $n,m$,分别表示该数列数字的个数和操作的总个数。
第二行包含 $n$ 个用空格分隔的整数,其中第 $i$ 个数字表示数列第 $i$ 项的初始值。
接下来 $m$ 行每行包含 $3$ 个整数,表示一个操作,具体如下:
- `1 x k` 含义:将第 $x$ 个数加上 $k$;
- `2 x y` 含义:输出区间 $[x,y]$ 内每个数的和。
## 输出格式
输出包含若干行整数,即为所有操作 $2$ 的结果。
## 输入输出样例 #1
### 输入 #1
```
5 5
1 5 4 2 3
1 1 3
2 2 5
1 3 -1
1 4 2
2 1 4
```
### 输出 #1
```
14
16
```
## 说明/提示
【数据范围】
对于 $30\%$ 的数据,$1 \le n \le 8$,$1\le m \le 10$;
对于 $70\%$ 的数据,$1\le n,m \le 10^4$;
对于 $100\%$ 的数据,$1\le n,m \le 5\times 10^5$,$1\le x\le y\le n$,$-2^{31}\le k<2^{31}$。
数据保证对于任意时刻,$a$ 的任意子区间(包括长度为 $1$ 和 $n$ 的子区间)和均在 $[-2^{31}, 2^{31})$ 范围内。
样例说明:
![](https://cdn.luogu.com.cn/upload/pic/2256.png)
故输出结果 $14$ 和 $16$。