#include<bits/stdc++.h>
using namespace std;
int n, m;
const int M = 5e5 + 9;
int tree[M];
void update(int x, int y) {
for (int pos = x;pos <= n;pos += pos & (-pos))
tree[pos] += y;
}
int ask(int x) {
int ans = 0;
for (int pos = x;pos;pos -= pos & (-pos))
ans += tree[pos];
return ans;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
int c;int last = 0;
//构造差分树
for (int i = 1;i <= n;i++)cin >> c, update(i, c - last), last = c;
while (m--) {
int a;cin >> a;
if (a == 1) {
int x, y, k;cin >> x >> y >> k;
update(x, k);
update(y + 1, -k);
}
else if (a == 2) {
int z;cin >> z;
cout << ask(z) << '\n';
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int M = 5e4 + 9;
int a[M], b[M], c[M];//数,最大,最小
int n, q;
void update(int x, int y) {
for (;x <= n;x += x & (-x)) {
b[x] = max(b[x], y);
c[x] = min(c[x], y);
}
}
int query(int l, int r) {
int mi = 2e9;int ma = INT_MIN;
while (l <= r) {
for (;r - (r & (-r)) >= l;r -= r & (-r))mi = min(mi, c[r]), ma = max(ma, b[r]);
mi = min(mi, a[r]);
ma = max(ma, a[r]);
r--;
}
return ma - mi;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> q;
for (int i = 0;i < M;i++)c[i] = INT_MAX;
for (int i = 1;i <= n;i++) {
cin >> a[i];
update(i, a[i]);
}
while (q--) {
int le, ri;cin >> le >> ri;
cout << query(le, ri) << '\n';
}
return 0;
}