#include #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define ALL(v) (v).begin(), (v).end() #define LLA(v) (v).rbegin(), (v).rend() #define SZ(v) (v).size() #define INT(...) \ int __VA_ARGS__; \ read(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ read(__VA_ARGS__) #define DOUBLE(...) \ double __VA_ARGS__; \ read(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ read(__VA_ARGS__) #define STRING(...) \ string __VA_ARGS__; \ read(__VA_ARGS__) #define VEC(type, name, size) \ vector name(size); \ read(name) using namespace std; using ll = long long; using pii = pair; using pll = pair; using Graph = vector>; template struct edge { int to; T cost; edge(int t, T c) : to(t), cost(c) {} }; template using WGraph = vector>>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; template inline vector make_vec(size_t a, T val) { return vector(a, val); } template inline auto make_vec(size_t a, Ts... ts) { return vector(a, make_vec(ts...)); } void read() {} template inline void read(T &a) { cin >> a; } template inline void read(pair &p) { read(p.first), read(p.second); } template inline void read(vector &v) { for(auto &a : v) read(a); } template inline void read(Head &head, Tail &...tail) { read(head), read(tail...); } template inline void chmax(T &a, T b) { (a < b ? a = b : a); } template inline void chmin(T &a, T b) { (a > b ? a = b : a); } /* SegmentTree(0-indexed) */ template struct SegmentTree { using F = function; const F f; const Monoid e; int n; vector dat; SegmentTree(int _n, const F _f, const Monoid &_e) : f(_f), e(_e) { n = 1; while(n < _n) n *= 2; dat.assign(2 * n, e); } SegmentTree(vector v, const F _f, const Monoid &_e) : f(_f), e(_e) { int sz = v.size(); n = 1; while(n < sz) n *= 2; dat.resize(2 * n); for(int i = 0; i < sz; i++) set(i, v[i]); build(); } void set(int k, Monoid a) { dat[k + n] = a; } void build() { for(int i = n - 1; i > 0; i--) { dat[i] = f(dat[2 * i], dat[2 * i + 1]); } } void update(int k, const Monoid &a) { k += n; dat[k] = a; while(k >>= 1) { dat[k] = f(dat[k * 2], dat[k * 2 + 1]); } } Monoid at(int a) { return query(a, a + 1); } // query for [a,b) Monoid query(int a, int b) { Monoid vl = e, vr = e; a += n, b += n; for(; a < b; a >>= 1, b >>= 1) { if(a & 1) vl = f(vl, dat[a++]); if(b & 1) vr = f(dat[--b], vr); } return f(vl, vr); } }; // Range min Query // http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4865222 // template struct RminQ : SegmentTree { // static auto f(Monoid a, Monoid b) { return min(a, b); } // RminQ(int n, const Monoid &e = numeric_limits::max()) // : SegmentTree(n, f, e) {} // RminQ(vector v, const Monoid &e = numeric_limits::max()) // : SegmentTree(v, f, e) {} // }; // // Range sum Query // // https://judge.yosupo.jp/submission/24445 // template struct RsumQ : SegmentTree { // static auto f(Monoid a, Monoid b) { return a + b; } // RsumQ(int n, const Monoid &e = 0) : SegmentTree(n, f, e) {} // RsumQ(vector v, const Monoid &e = 0) // : SegmentTree(v, f, e) {} // }; using S = int; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); INT(n, q); VEC(ll, a, n); vector b; b.push_back(INF); for(int i = 0; i < n - 1; i++) { b.push_back(a[i + 1] - a[i]); } b.push_back(INF); auto op = [](S a, S b) { return a + b; }; S e = 0; SegmentTree segtree(n + 1, op, e); rep(i, n + 1) { if(b[i] != 0) segtree.set(i, 1); } segtree.build(); rep(i, q) { INT(qq); if(qq == 1) { INT(l, r, x); l--; b[l] += x; b[r] -= x; segtree.update(l, b[l] != 0); segtree.update(r, b[r] != 0); } else { INT(l, r); l--; cout << segtree.query(l, r) << endl; } } }