2022-11-20 08:52:14 +00:00
|
|
|
#include <iostream>
|
2020-12-02 07:07:01 +00:00
|
|
|
|
2022-11-20 08:52:14 +00:00
|
|
|
using std::cin;
|
|
|
|
using std::cout;
|
|
|
|
const char endl = '\n';
|
2020-12-02 07:07:01 +00:00
|
|
|
|
2022-11-20 08:52:14 +00:00
|
|
|
const int N = 5e5 + 5;
|
2020-12-02 07:07:01 +00:00
|
|
|
|
2022-11-20 08:52:14 +00:00
|
|
|
int n, m, c[N];
|
2022-05-20 01:23:27 +00:00
|
|
|
|
2022-11-20 08:52:14 +00:00
|
|
|
int lowbit(int x) {
|
|
|
|
return x & -x;
|
2020-12-02 07:07:01 +00:00
|
|
|
}
|
|
|
|
|
2022-11-20 08:52:14 +00:00
|
|
|
void add(int x, int y) {
|
|
|
|
for (; x <= n; x += lowbit(x)) c[x] += y;
|
2020-12-02 07:07:01 +00:00
|
|
|
}
|
|
|
|
|
2022-11-20 08:52:14 +00:00
|
|
|
int sum(int x) {
|
|
|
|
int res = 0;
|
|
|
|
for (; x; x -= lowbit(x)) res += c[x];
|
|
|
|
return res;
|
2020-12-02 07:07:01 +00:00
|
|
|
}
|
|
|
|
|
2022-11-20 08:52:14 +00:00
|
|
|
int main() {
|
|
|
|
std::ios::sync_with_stdio(false);
|
|
|
|
cin.tie(nullptr);
|
2020-12-02 07:07:01 +00:00
|
|
|
|
2022-11-20 08:52:14 +00:00
|
|
|
cin >> n >> m;
|
2020-12-02 07:07:01 +00:00
|
|
|
|
2022-11-20 08:52:14 +00:00
|
|
|
for (int i = 1, x; i <= n; i++) {
|
|
|
|
cin >> x;
|
|
|
|
|
|
|
|
add(i, x);
|
|
|
|
add(i + 1, -x);
|
2020-12-02 07:07:01 +00:00
|
|
|
}
|
2022-11-20 08:52:14 +00:00
|
|
|
|
2020-12-02 07:07:01 +00:00
|
|
|
while (m--) {
|
2022-11-20 08:52:14 +00:00
|
|
|
int op;
|
|
|
|
|
|
|
|
cin >> op;
|
|
|
|
|
2020-12-02 07:07:01 +00:00
|
|
|
if (op == 1) {
|
2022-11-20 08:52:14 +00:00
|
|
|
int x, y, k;
|
|
|
|
|
|
|
|
cin >> x >> y >> k;
|
|
|
|
|
|
|
|
add(x, k);
|
|
|
|
add(y + 1, -k);
|
|
|
|
} else { // op == 2
|
|
|
|
int x;
|
|
|
|
|
|
|
|
cin >> x;
|
|
|
|
|
|
|
|
cout << sum(x) << endl;
|
2020-12-02 07:07:01 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-20 08:52:14 +00:00
|
|
|
|
2020-12-02 07:07:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|