#include #include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; /*-------------------------------------------------*/ template struct RAQ { RAQ(int n_, const Abelian UNITY = 0) : n(n_), UNITY(UNITY) { ++n; dat.assign(n, UNITY); } void add(int left, int right, Abelian value) { while (left < n) { dat[left] += value; left += left & -left; } ++right; while (right < n) { dat[right] += -value; right += right & -right; } } Abelian query(int idx) { Abelian res = UNITY; while (idx > 0) { res += dat[idx]; idx -= idx & -idx; } return res; } private: int n; const Abelian UNITY; vector dat; }; template struct RSQ { RSQ(int sz, const Monoid &UNITY = 0) : UNITY(UNITY) { init(sz); dat.assign((n << 1) - 1, UNITY); } RSQ(const vector &a, const Monoid &UNITY = 0) : UNITY(UNITY) { int a_sz = a.size(); init(a_sz); dat.resize((n << 1) - 1); REP(i, a_sz) dat[n - 1 + i] = a[i]; for (int i = n - 2; i >= 0; --i) dat[i] = dat[(i << 1) + 1] + dat[(i << 1) + 2]; } void add(int node, Monoid value) { node += n - 1; dat[node] += value; while (node > 0) { node = (node - 1) >> 1; dat[node] = dat[(node << 1) + 1] + dat[(node << 1) + 2]; } } Monoid sum(int a, int b) { return sum(a, b, 0, 0, n); } inline Monoid operator[](const int idx) const { return dat[idx + n - 1]; } int find(int a, int b, Monoid value) { return find(a, b, value, 0, 0, n); } private: int n = 1; const Monoid UNITY; vector dat; void init(int sz) { while (n < sz) n <<= 1; } Monoid sum(int a, int b, int node, int left, int right) { if (right <= a || b <= left) return UNITY; if (a <= left && right <= b) return dat[node]; return sum(a, b, (node << 1) + 1, left, (left + right) >> 1) + sum(a, b, (node << 1) + 2, (left + right) >> 1, right); } int find(int a, int b, Monoid value, int node, int left, int right) { if (dat[node] < value || right <= a || b <= left) return -1; if (right - left == 1) return node - (n - 1); int res_l = find(a, b, value, (node << 1) + 1, left, (left + right) >> 1); if (res_l != -1) return res_l; return find(a, b, value, (node << 1) + 2, (left + right) >> 1, right); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int n, q; cin >> n >> q; RSQ rsq(n); RAQ raq(n); REP(i, n) { int a; cin >> a; raq.add(i + 1, i + 1, a); if (i > 0 && a == raq.query(i)) rsq.add(i - 1, 1); } while (q--) { int query, l, r; cin >> query >> l >> r; if (query == 1) { int x; cin >> x; if (l - 1 > 0 && raq.query(l - 1) == raq.query(l)) rsq.add(l - 2, -1); if (r + 1 <= n && raq.query(r) == raq.query(r + 1)) rsq.add(r - 1, -1); raq.add(l, r, x); if (l - 1 > 0 && raq.query(l - 1) == raq.query(l)) rsq.add(l - 2, 1); if (r + 1 <= n && raq.query(r) == raq.query(r + 1)) rsq.add(r - 1, -1); } else { cout << r - l - rsq.sum(l - 1, r - 1) + 1 << '\n'; } // REP(i, n) cout << raq.query(i + 1) << ' '; // cout << '\n'; // REP(i, n) cout << rsq[i] << ' '; // cout << '\n'; } return 0; }