#include using namespace std; using lint = long long int; using pint = pair; using plint = pair; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) template void ndarray(vector &vec, int len) { vec.resize(len); } template void ndarray(vector &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); } template bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; } template bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; } template pair operator+(const pair &l, const pair &r) { return make_pair(l.first + r.first, l.second + r.second); } template pair operator-(const pair &l, const pair &r) { return make_pair(l.first - r.first, l.second - r.second); } template istream &operator>>(istream &is, vector &vec){ for (auto &v : vec) is >> v; return is; } ///// This part below is only for debug, not used ///// template ostream &operator<<(ostream &os, const vector &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template ostream &operator<<(ostream &os, const deque &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template ostream &operator<<(ostream &os, const set &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_set &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const multiset &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_multiset &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const pair &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; } template ostream &operator<<(ostream &os, const map &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_map &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; ///// END ///// /* #include #include #include using namespace __gnu_pbds; // find_by_order(), order_of_key() template using pbds_set = tree, rb_tree_tag, tree_order_statistics_node_update>; template using pbds_map = tree, rb_tree_tag, tree_order_statistics_node_update>; */ template struct SegTree { int N; int head; vector x; T defaultT; using func = function; func merger; T _get(int begin, int end, int pos, int l, int r) const { if (r <= begin or l >= end) return defaultT; if (l >= begin and r <= end) return x[pos]; return merger(_get(begin, end, 2 * pos + 1, l, (l + r) / 2), _get(begin, end, 2 * pos + 2, (l + r) / 2, r)); } SegTree(int N, T defaultT, func merger) : N(N), defaultT(defaultT), merger(merger) { int N_tmp = 1; while (N_tmp < N) N_tmp <<= 1; x.assign(N_tmp*2, defaultT), head = N_tmp - 1; } SegTree(const vector &vals, T defaultT, func merger) : N(vals.size()), defaultT(defaultT), merger(merger) { int N_tmp = 1; while (N_tmp < N) N_tmp <<= 1; x.assign(N_tmp*2, defaultT), head = N_tmp - 1; copy(vals.begin(), vals.end(), x.begin() + head); IREP(i, head) x[i] = merger(x[i * 2 + 1], x[i * 2 + 2]); } SegTree() : SegTree(0, T(), [](T, T) { return T(); }) {} void build(const vector &vals) { copy(vals.begin(), vals.end(), x.begin() + head); IREP(i, head) x[i] = merger(x[i * 2 + 1], x[i * 2 + 2]); } void update(int pos, T val) { pos += head, x[pos] = val; while (pos) pos = (pos - 1) / 2, x[pos] = merger(x[pos*2+1], x[pos*2+2]); } T get(int begin, int end) const { return _get(begin, end, 0, 0, (int)x.size() / 2); } friend ostream &operator<<(ostream &os, const SegTree &s) { os << "["; REP(i, s.N) os << s.get(i, i + 1) << ","; os << "]"; return os; } }; // 参考 要素数N・非負入力を想定したRange Maximum Query // SegTree rMq(N, 0, [](int a, int b) { return max(a, b); }); struct Node { bool leaf; int tot; lint diff; Node(): leaf(false), tot(0), diff(0) {} }; int main() { int N, Q; cin >> N >> Q; vector a(N); cin >> a; vector b(N); b[0].tot = 1; REP(i, N - 1) { b[i + 1].leaf = true; b[i + 1].diff = a[i + 1] - a[i]; } SegTree st(b, Node(), [](const Node &l, const Node &r) { Node ret; ret.leaf = false; ret.tot = l.tot + r.tot + l.leaf * !!l.diff + r.leaf * !!r.diff; ret.diff = 0; return ret; }); REP(_, Q) { int q; cin >> q; if (q == 1) { int l, r, x; cin >> l >> r >> x; l--; b[l].diff += x; st.update(l, b[l]); if (r < N) { b[r].diff -= x; st.update(r, b[r]); } } else { int l, r; cin >> l >> r; cout << st.get(l - 1, r).tot << endl; } } }