-
Notifications
You must be signed in to change notification settings - Fork 0
/
P3368.cpp
46 lines (42 loc) · 965 Bytes
/
P3368.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// Created by lsk on 6/11/24.
//
#include <iostream>
#define lowbit(a) (a & (-a))
#define MAX 500010
int treearr[MAX] = {0}, input[MAX] = {0};
int len = 0;
void update(int i, int d) {
while (i <= len) {
treearr[i] += d;
i += lowbit(i);
}
}
int query(int i) {
int result = 0;
while (i > 0) {
result += treearr[i];
i -= lowbit(i);
}
return result;
}
int main() {
int optCount; std::cin >> len >> optCount;
input[0] = 0;
for (int i = 1; i <= len; i++) std::cin >> input[i];
for (int i = 1; i <= len; i++) {
update(i, input[i]-input[i-1]);
}
for (int i = 0; i < optCount; i++) {
int opt; std::cin >> opt;
if (opt == 1) {
int x, y, d; std::cin >> x >> y >> d;
update(x, d);
update(y+1, -d);
} else {
int index; std::cin >> index;
printf("%d\n", query(index));
}
}
return 0;
}