You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
const int N = 5e5 + 10;
|
|
|
|
|
int a[N]; // a是原数组。c是差分数组,用树状数组维护
|
|
|
|
|
|
|
|
|
|
int n, m;
|
|
|
|
|
// 树状数组模板
|
|
|
|
|
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() {
|
|
|
|
|
#ifndef ONLINE_JUDGE
|
|
|
|
|
freopen("P3368.in", "r", stdin);
|
|
|
|
|
#endif
|
|
|
|
|
scanf("%d %d", &n, &m);
|
|
|
|
|
|
|
|
|
|
// 原数组
|
|
|
|
|
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
|
|
|
|
|
|
|
|
|
|
// 保存差分数组
|
|
|
|
|
for (int i = 1; i <= n; i++) add(i, a[i] - a[i - 1]);
|
|
|
|
|
|
|
|
|
|
int op, l, r, v, k;
|
|
|
|
|
while (m--) {
|
|
|
|
|
scanf("%d", &op);
|
|
|
|
|
if (op == 1) {
|
|
|
|
|
scanf("%d %d %d", &l, &r, &v);
|
|
|
|
|
add(l, v), add(r + 1, -v);
|
|
|
|
|
} else {
|
|
|
|
|
scanf("%d", &k);
|
|
|
|
|
// 树状数组维护的是变化量,还需要加上原来的值
|
|
|
|
|
printf("%d\n", sum(k)); // 求某点的值
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|