#include #include #include #include #include #include #include #include using namespace std; #define int long long #define endl "\n" const long long INF = (long long)1e18; const long long MOD = 1'000'000'007; string yn(bool f){return f?"Yes":"No";} string YN(bool f){return f?"YES":"NO";} template class lazy_segment_tree{ int n; T fval; function operation; vector dat, lazy; public: lazy_segment_tree(){ } lazy_segment_tree(int n_, T val, function fun){ init(n_, val, fun); } ~lazy_segment_tree(){ } void init(int n_, T val, function fun){ fval = val; operation = fun; n = 1; while(n < n_) n *= 2; dat.resize(2 * n - 1); lazy.resize(2 * n - 1, fval); for(int i = 0; i < 2 * n - 1; i++) dat[i] = fval; } void eval(int k, int l, int r){ if(lazy[k] != fval){ dat[k] = operation(dat[k], lazy[k]); if(r - l > 1) { lazy[2*k+1] = operation(lazy[2*k+1], lazy[k]/2); lazy[2*k+2] = operation(lazy[2*k+2], lazy[k]/2); } lazy[k] = fval; } } void update(int a, int b, T x, int k = 0, int l = 0, int r = -1){ if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) {return ;} if(a <= l && r <= b){ lazy[k] = operation(lazy[k], (r - l) * x); eval(k, l, r); } else { update(a, b, x, 2*k+1, l, (l+r)/2); update(a, b, x, 2*k+2, (l+r)/2, r); dat[k] = operation(dat[2*k+1], dat[2*k+2]); } } T query(int a, int b, int k = 0, int l = 0, int r = -1){ if(r < 0) r = n; eval(k, l, r); if(r <= a || b <= l){ return fval; } if(a <= l && r <= b){ return dat[k]; }else { T vl = query(a, b, k * 2 + 1, l, (l + r) / 2 ); T vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return operation(vl, vr); } } }; template class segment_tree{ int n; T fval; function operation; vector dat; T _query(int a, int b, int k, int l, int r){ if(r <= a || b <= l){ return fval; } if(a <= l && r <= b){ return dat[k]; }else { T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2 ); T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r); return operation(vl, vr); } } public: segment_tree(){ } segment_tree(int n_, T val, function fun){ init(n_, val, fun); } ~segment_tree(){ } void init(int n_, T val, function fun){ fval = val; operation = fun; n = 1; while(n < n_) n *= 2; dat.resize(2 * n - 1); for(int i = 0; i < 2 * n - 1; i++) dat[i] = fval; } void update(int k, T a){ k += n - 1; dat[k] = a; while(k > 0){ k = (k - 1) / 2; dat[k] = operation(dat[k*2 + 1],dat[k*2 + 2]); } } T query(int a, int b){ return _query(a, b, 0, 0, n); } }; signed main(){ // cin.tie(0); // ios::sync_with_stdio(false); // cout< lseg; segment_tree seg; int N, Q; vector A; cin>>N>>Q; lseg.init(N+2,0,[](int first, int second){ return first + second;}); seg.init(N+2,0, [](int first, int second){ return first + second;}); A.resize(N); for(int i = 0; i < N; i++){ cin>>A[i]; if(i){ if(A[i-1] != A[i]){ seg.update(i, 1); } } } for(int i = 0; i < Q; i++){ int c, l, r, x; cin>>c>>l>>r; l--, r--; if(c == 1){ cin>>x; lseg.update(l, r+1, x); int l1, l2, r1, r2; // if(l == 0 && r == 0){ // r1 = lseg.query(r, r+1); // r2 = lseg.query(r+1, r+2); // l2 = lseg.query(l, l+1); // if(r1 == r2) { // seg.update(r2, 0); // } else { // seg.update(r2, 1); // } // } else if(l == 0) { r1 = lseg.query(r, r+1); r2 = lseg.query(r+1, r+2); // l2 = lseg.query(l, l+1); if(r1 == r2) { seg.update(r+1, 0); } else { seg.update(r+1, 1); } } else { l1 = lseg.query(l, l+1); l2 = lseg.query(l-1, l); r1 = lseg.query(r, r+1); r2 = lseg.query(r+1, r+2); if(l1 == l2) { seg.update(l, 0); } else { seg.update(l, 1); } if(r1 == r2) { seg.update(r+1, 0); } else { seg.update(r+1, 1); } } } else { cout<