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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
#define ls (now << 1)
#define rs (now << 1 | 1)
#define int long long
int n, m;
int a[N];
struct Node {
int len, sum, tag;
} tr[N << 2];
Node operator + (const Node &l, const Node &r) {
Node a;
a.sum = l.sum + r.sum;
a.tag = 0;
a.len = l.len + r.len;
return a;
}
void update(int now) {
tr[now] = tr[ls] + tr[rs];
}
void settag(int now, int k) {
tr[now].tag += k;
tr[now].sum += tr[now].len * k;
}
void pushdown(int now) {
if (tr[now].tag) {
settag(ls, tr[now].tag);
settag(rs, tr[now].tag);
tr[now].tag = 0;
}
}
void build(int now, int l, int r) {
if (l == r) {
tr[now] = {1, a[l], 0};
return;
}
int mid = (l + r) >> 1;
build(ls, l, mid);
build(rs, mid + 1, r);
update(now);
}
void modify(int now, int l, int r, int s, int t, int val) {
if (l <= s && r >= t) {
settag(now, val);
return;
}
pushdown(now);
int mid = (s + t) >> 1;
if (l <= mid) modify(ls, l, r, s, mid, val);
if (r > mid) modify(rs, l, r, mid + 1, t, val);
update(now);
}
int query(int now, int l, int r, int s, int t) {
if (l <= s && r >= t) return tr[now].sum;
pushdown(now);
int mid = (s + t) >> 1;
int ans = 0;
if (l <= mid) ans += query(ls, l, r, s, mid);
if (r > mid) ans += query(rs, l, r, mid + 1, t);
return ans;
}
signed main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
build(1, 1, n);
cin>>m;
while (m--) {
int op, x, y, z;
cin >> op;
if (op == 1) {
cin >> x >> y >> z;
modify(1, x, y, 1, n, z);
} else {
cin>>x;
cout << query(1, x, x, 1, n) << endl;
}
}
return 0;
}
|