#include ///////////////////// // Range Add Query // ///////////////////// template class RAddQ { private: std::vector container_; void build(const unsigned int array_size) { unsigned int length{1}; while (length < array_size) length <<= 1; container_.resize(2 * length); } public: RAddQ(const unsigned int array_size) { build(array_size); } RAddQ(const std::vector &array) { build(array.size()); std::copy(array.begin(), array.end(), container_.begin() + (container_.size() >> 1)); for (int i{((int)container_.size() >> 1) - 1}; i > 0; i--) container_[i] = container_[2 * i] + container_[2 * i + 1]; } // left,rightは0-indexed、[left, right)の半開区間 void update(const int left, const int right, const T added) { for (int left_i{std::max(0, left) + ((int)container_.size() >> 1)}, right_i{std::min((int)container_.size() >> 1, right) + ((int)container_.size() >> 1)}; left_i < right_i; left_i >>= 1, right_i >>= 1 ) { if (left_i & 1) { container_[left_i] += added; left_i++; } if (right_i & 1) { right_i--; container_[right_i] += added; } } } // indexは0-indexed T get(const int index) const { T sum{}; for (int add_place{index + ((int)container_.size() >> 1)}; add_place > 0; add_place >>= 1) sum += container_[add_place]; return sum; } }; /////////////////////////// // Range Sum Query (BIT) // /////////////////////////// class RSumQBIT { private: std::vector container_; int64_t getHelper(const int index) const { if (index < 0) return 0; if ((int)(container_.size()) <= index) return container_.back(); int64_t sum{}; for (int add_place{index}; add_place > 0; add_place -= add_place & -add_place) sum += container_[add_place]; return sum; } public: RSumQBIT(const int array_size) : container_(array_size + 1) {} // indexは0-indexed void update(const int index, const int64_t added) { for (int update_place{index + 1}; update_place < (int)(container_.size()); update_place += update_place & -update_place) container_[update_place] += added; } // left,rightは0-indexed、[left, right)の半開区間 int64_t get(const int left, const int right) const { return -getHelper(left) + getHelper(right); } }; int main() { int N, Q; scanf("%d%d", &N, &Q); std::vector a(N + 2); for (int i{1}; i <= N; i++) scanf("%lld", &a[i]); RAddQ<> raq(a); RSumQBIT bit(N + 2); for (int i{1}; i <= N; i++) if (a[i] != a[i + 1]) bit.update(i, 1); for (int q_i{}; q_i < Q; q_i++) { int com, left, right; scanf("%d%d%d", &com, &left, &right); right++; if (com == 1) { int64_t x; scanf("%lld", &x); raq.update(left, right, x); int64_t left_prev{bit.get(left - 1, left)}; if (raq.get(left - 1) != raq.get(left)) bit.update(left - 1, -left_prev + 1); else bit.update(left - 1, -left_prev); int64_t right_prev{bit.get(right - 1, right)}; if (raq.get(right - 1) != raq.get(right)) bit.update(right - 1, -right_prev + 1); else bit.update(right - 1, -right_prev); } else printf("%lld\n", bit.get(left, right - 1) + 1); } return 0; }