#include using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template inline string toString(T x) {ostringstream sout;sout< VI; typedef vector VVI; typedef vector VS; typedef pair P; typedef tuple tpl; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) const double EPS = 1e-9; const double PI = acos(-1.0); const int INT_INF = 2147483647; const long long LL_INF = 1LL<<60; const long long MOD = 1000000007; #define CLR(a) memset((a), 0 ,sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template struct LazySegmentTree{ typedef function F; typedef function G; typedef function H; typedef function P; int n; F f; G g; H h; P p; T d1; E d0; vector val; vector lazy; LazySegmentTree(vector a, F f_, G g_, H h_, T d1_, E d0_, P p_=[](E a,int b){return a;}): f(f_),g(g_),h(h_),d1(d1_),d0(d0_),p(p_){ int sz = a.size(); n = 1; while (n < sz) n <<= 1; val.clear(); val.resize(2 * n - 1, d1); lazy.clear(); lazy.resize(2 * n - 1, d0); for (int i = 0; i < sz; i++) val[i + n - 1] = a[i]; for (int i = n - 2; i >= 0; i--) val[i] = f(val[i * 2 + 1], val[i * 2 + 2]); } inline void eval(int len, int k){ if(lazy[k] == d0) return; if(2*k+1 < 2*n-1){ lazy[2*k+1] = h(lazy[2*k+1], lazy[k]); lazy[2*k+2] = h(lazy[2*k+2], lazy[k]); } val[k] = g(val[k], p(lazy[k], len)); lazy[k] = d0; } void update(int a, int b, E x, int k=0, int l=0, int r=-1){ if(r < 0) r = n; eval(r-l, k); if(r <=a || b <= l) return; if(a <= l && r <= b){ lazy[k] = h(lazy[k], x); eval(r-l, k); } else{ update(a, b, x, 2*k+1, l, (l+r)/2); update(a, b, x, 2*k+2, (l+r)/2, r); val[k] = f(val[2*k+1], val[2*k+2]); } } T query(int a, int b, int k=0, int l=0, int r=-1){ if(r < 0) r = n; eval(r-l, k); if(r <= a || b <= l) return d1; if(a <= l && r <= b) return val[k]; T val_l = query(a, b , 2*k+1, l, (l+r)/2); T val_r = query(a, b , 2*k+2, (l+r)/2, r); return f(val_l, val_r); } }; int main(void){ auto f = [](tpl a, tpl b){ tpl res(get<0>(a)+get<0>(b), get<1>(a), get<2>(b)); if(get<2>(a) == get<1>(b)) get<0>(res)--; if(get<1>(res)==-1){get<1>(res) = get<1>(b); get<0>(res)--;} if(get<2>(res)==-1){get<2>(res) = get<2>(a); get<0>(res)--;} return res; }; auto g = [](tpl a, ll b){get<1>(a) += b; get<2>(a) += b; return a;}; auto h = [](ll a, ll b){return b;}; auto p = [](ll a, ll b){return a;}; int n,q; cin >> n >> q; vector a(n); REP(i,n){ ll x; cin >> x; get<0>(a[i]) = 1; get<1>(a[i]) = x; get<2>(a[i]) = x; } LazySegmentTree st(a, f, g, h, tpl(1,-1,-1), 0, p); REP(i,q){ int c; cin >> c; if(c == 1){ ll s, t, x; cin >> s >> t >> x; s--; t--; st.update(s, t+1, x); } else{ int s,t; cin >> s >> t; s--; t--; tpl ans = st.query(s,t+1); cout << get<0>(ans) << endl; } } return 0; }