'commit'
This commit is contained in:
37
TangDou/AcWing/BIT/P3374.cpp
Normal file
37
TangDou/AcWing/BIT/P3374.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int N = 5 * 1e5 + 10;
|
||||
int n, m;
|
||||
int a[N];
|
||||
|
||||
// 树状数组模板
|
||||
typedef long long LL;
|
||||
#define lowbit(x) (x & -x)
|
||||
int c[N];
|
||||
void add(int x, int d) {
|
||||
for (int i = x; i < N; i += lowbit(i)) c[i] += d;
|
||||
}
|
||||
LL sum(int x) {
|
||||
LL res = 0;
|
||||
for (int i = x; i; i -= lowbit(i)) res += c[i];
|
||||
return res;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i], add(i, a[i]); // 维护进入树状数组,两个概念:位置,值
|
||||
|
||||
while (m--) {
|
||||
int op, x, y;
|
||||
cin >> op >> x >> y;
|
||||
if (op == 1)
|
||||
add(x, y); // 在x位置上加上y
|
||||
else
|
||||
// 计算[x,y]之间的数字和
|
||||
cout << sum(y) - sum(x - 1) << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user