#include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; const ll MOD = 1000000007LL; template class SegmentTree { using F = function; int n; F f; T t; vector dat; public: SegmentTree() {}; SegmentTree(F f, T t) : f(f), t(t) {} void init(int n_) { n = 1; while (n < n_) n <<= 1; dat.assign(n << 1, t); } void build(const vector &v) { auto n_ = (int)v.size(); init(n_); for (int i = 0; i < n_; i++) dat[n + i] = v[i]; for (int i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } void set_val(int k, T x) { dat[k += n] = x; while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]); } T query(int a, int b) { T vl = t, vr = t; for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) { if (l & 1) vl = f(vl, dat[l++]); if (r & 1) vr = f(dat[--r], vr); } return f(vl, vr); } }; typedef pair P; int main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; vector a(n); vector

b(n); for (int i = 0; i < n; i++) { cin >> a[i]; if (i) { b[i].first = a[i] - a[i - 1]; b[i].second = b[i].first != 0; } } auto f = [](P a, P b) { return P(a.first, a.second + b.second); }; SegmentTree

seg(f, P(-1, 0)); seg.build(b); while (q--) { ll c, l, r, x; cin >> c >> l >> r; if (c == 1) { cin >> x; ll lv = seg.query(l - 1, l).first; ll rv = seg.query(r - 1, r).first; seg.set_val(l - 1, P(lv + x, lv + x != 0)); seg.set_val(r, P(rv - x, rv - x != 0)); } else { cout << seg.query(l, r).second + 1 << '\n'; } } return 0; }