#include "bits/stdc++.h" #define ALL(obj) (obj).begin(),(obj).end() #define RALL(obj) (obj).rbegin(),(obj).rend() #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define REPR(i, n) for(int i = (int)(n); i >= 0; i--) #define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++) using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = MOD - 1; const ll LLINF = 4e18; template struct SegmentTree { private: using Func = function; const Func F; const Monoid UNITY; int n; vector node,cnt0; public: //m=size, f=[](M a,M b){return ;} SegmentTree(int m, const Func f, const Monoid &unity) : F(f), UNITY(unity) { n = 1; while (n < m) n <<= 1; node.resize(n * 2 - 1, UNITY); } SegmentTree(const vector& v, const Func f, const Monoid &unity) : F(f), UNITY(unity) { int sz = v.size(); n = 1; while (n < sz) n <<= 1; node.resize(n * 2 - 1, UNITY); REP(i, sz) { if (v[i] != 0) node[i + n - 1] = 1; } REPR(i, n - 2) { node[i] = F(node[2 * i + 1], node[2 * i + 2]); } } // 0-indexed void update(int x, int val) { if (x >= n || x < 0) return; x += n - 1; if (val == 0) node[x] = 0; else node[x] = 1; while (x > 0) { x = (x - 1) >> 1; node[x] = F(node[2 * x + 1], node[2 * x + 2]); } } // [a,b) Monoid get(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return 0; if (a <= l && r <= b) return node[k]; int vl = get(a, b, 2 * k + 1, l, (r - l) / 2 + l); int vr = get(a, b, 2 * k + 2, (r - l) / 2 + l, r); return F(vl,vr); } Monoid operator[](int k) const { if (0 <= k || k < n) return node[n + k - 1]; else return UNITY; } }; int main() { int n,q; cin >> n >> q; vector a(n),b(n-1); REP(i, n) cin >> a[i]; REP(i, n - 1) b[i] = a[i + 1] - a[i]; SegmentTree seg(b, [](int a, int b){ return a+b; }, 0); REP(i, q) { int t, l, r; cin >> t >> l >> r; l--; r--; if (t == 1) { int x; cin >> x; if (l > 0) { seg.update(l - 1, b[l-1] + x); b[l - 1] += x; } if (r < n - 1) { seg.update(r, b[r] - x); b[r] -= x; } } else { cout << seg.get(l, r)+1 << endl; } } getchar(); getchar(); }