#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; template struct SegmentTree { private: int siz; vector node; public: SegmentTree(int n) noexcept { siz = 1; while(siz < n) siz <<= 1; node.assign(2*siz-1,e()); } void replace(int pos,T x) noexcept {func_update(pos,x,[](T u,T v){return u = v;});} void add(int pos,T x) noexcept {func_update(pos,x,[](T u,T v){return u+v;});} void func_update(int pos,T x) noexcept {func_update(pos,x,op);} void func_update(int pos,T x,T (*func)(T,T)) noexcept { assert(0 <= pos && pos < siz); pos += siz - 1; node[pos] = func(node[pos],x); while(pos) { pos = (pos-1)/2; node[pos] = op(node[2*pos+1],node[2*pos+2]); } } T operator [](int pos) noexcept { assert(0 <= pos && pos < siz); return node[pos+siz-1]; } T prod(int l,int r) noexcept { assert(0 <= l && l <= r && r <= siz); l += siz-1; r += siz-1; T Lval = e(); T Rval = e(); while(l < r) { if(!(l & 1)) Lval = op(Lval,node[l++]); if(!(r & 1)) Rval = op(node[--r],Rval); l >>= 1; r >>= 1; } return op(Lval,Rval); } T prod() noexcept {return node[0];} }; template struct LazySegmentTree { private: vector node; vector lazy; int siz,log; void map_and_comp(F f,int u) { node[u] = mapping(f,node[u]); if(u < siz) lazy[u] = composition(f,lazy[u]); } void propagate(int u) { assert(0 <= u && u < siz); map_and_comp(lazy[u],2*u); map_and_comp(lazy[u],2*u+1); lazy[u] = id(); } void recalculate(int u) {node[u] = op(node[2*u],node[2*u+1]);} public: LazySegmentTree(int n) { siz = 1; log = 0; while(siz < n) siz <<= 1,log++; node.assign(2*siz,e()); lazy.assign(siz,id()); } void fill(T x,int l = 0,int r = -1) {if(r < 0){r = siz;} for(int i = l;i < r;i++) replace(i,x);} void clear() {fill(e());} void replace(int pos,T x) {func_update(pos,x,[](T u,T v){return u = v;});} void add(int pos,T x) {func_update(pos,x,[](T u,T v){return u + v;});} void func_update(int pos,T x,T (*func)(T,T)) { assert(0 <= pos && pos < siz); pos += siz; for(int i = log;i >= 1;i--) propagate(pos >> i); node[pos] = func(node[pos],x); for(int i = 1;i <= log;i++) recalculate(pos >> i); } T operator[](int pos) { assert(0 <= pos && pos < siz); pos += siz; for(int i = log;i >= 1;i--) propagate(pos >> i); return node[pos]; } void apply(int pos,F f) { assert(0 <= pos && pos < siz); pos += siz; for(int i = log;i >= 1;i--) propagate(pos >> i); node[pos] = mapping(f,node[pos]); for(int i = 1;i <= log;i++) recalculate(pos >> i); } void apply(int l,int r,F f) { assert(0 <= l && l <= r && r <= siz); if(l == r) return; l += siz; r += siz; int l0 = l/(l & -l); int r0 = r/(r & -r); for(int i = log;i >= 1;i--) propagate(l0 >> i); for(int i = log;i >= 1;i--) propagate((r0-1) >> i); while(l < r) { if(l & 1) map_and_comp(f,l++); if(r & 1) map_and_comp(f,--r); l >>= 1; r >>= 1; } for(int i = 1;i <= log;i++) recalculate(l0 >> i); for(int i = 1;i <= log;i++) recalculate((r0-1) >> i); } T prod() {return node[1];} T prod(int l,int r) { assert(0 <= l && l <= r && r <= siz); l += siz; r += siz; int l0 = l/(l & -l); int r0 = r/(r & -r); for(int i = log;i >= 1;i--) propagate(l0 >> i); for(int i = log;i >= 1;i--) propagate((r0-1) >> i); T Lval = e(),Rval = e(); while(l < r) { if(l & 1) Lval = op(Lval,node[l++]); if(r & 1) Rval = op(node[--r],Rval); l >>= 1; r >>= 1; } return op(Lval,Rval); } }; struct dat { long long l,r; int cnt; }; dat op(dat a,dat b) { dat x; x.l = a.l; x.r = b.r; x.cnt = a.cnt + b.cnt; if(a.r == b.l) x.cnt++; return x; } dat e() {return dat{-1,-1,0};} dat mp(long long f,dat x) { dat y; y.l = x.l + f; y.r = x.r + f; y.cnt = x.cnt; return y; } long long cp(long long f,long long g) {return f+g;} long long id() {return 0;} int N,Q; void solve() { cin >> N >> Q; LazySegmentTree seg(N); for(int i = 0;i < N;i++) { int A; cin >> A; seg.replace(i,dat{A,A,0}); } for(;Q--;) { int t; cin >> t; if(t == 1) { int l,r,x; cin >> l >> r >> x; l--; seg.apply(l,r,x); } else { int l,r; cin >> l >> r; l--; cout << r-l-seg.prod(l,r).cnt << "\n"; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; //cin >> tt; while(tt--) solve(); }