数列分块
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
int id[N], len;
int a[N], b[N], s[N];
void add(int l, int r, int c) {
int sid = id[l], eid = id[r];
if (sid == eid) {
for (int i = l ; i <= r; i++)
a[i] += c, s[ sid ] += c;
return ;
}
for (int i = l ; id[i] == sid ; i++)
a[i] += c, s[ sid ] += c;
for (int i = sid + 1; i < eid ; i ++)
b[i] += c, s[ i ] += c * len;
for (int i = r ; id[i] == eid ; i--)
a[i] += c, s[ eid ] += c;
}
int query(int x) {
return a[x] + b[ id[x] ];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
len = sqrt(n);
for (int i = 1 ; i <= n ; i++) {
cin >> a[i];
id[i] = (i - 1) / len + 1;
s[ id[i] ] += a[i];
}
for (int i = 0 ; i < n ; i++) {
int op, l, r, c;
cin >> op >> l >> r >> c;
if (op == 0) {
add(l, r, c);
} else {
cout << query(r) << endl;
}
}
return 0;
}