#include #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define all(c) c.begin(),c.end() #define pb push_back #define fs first #define sc second #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) using namespace std; template ostream& operator<<(ostream& o,const pair &p){ return o<<"("< ostream& operator<<(ostream& o,const vector &vc){ o<<"{"; for(const T& v:vc) o< using V = vector; template using VV = vector>; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); } #ifdef LOCAL #define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl #else #define show(x) true #endif struct segtree{ using D = int; int N; vector val; segtree(){} segtree(int n){ N=1; while(N& ds){ int n = ds.size(); N=1; while(N0;i--) val[i] = val[i*2] + val[i*2+1]; } void assign(int k,D d){ k+=N; val[k]=d; k/=2; while(k){ val[k] = val[k*2] + val[k*2+1]; k/=2; } } D sum(int a,int b){ //non-commutative & unrecursive D res = 0; a+=N,b+=N; while(a> N >> Q; V d(N-1); segtree seg(N-1); { V a(N); rep(i,N) cin >> a[i]; rep(i,N-1) d[i] = a[i+1] - a[i]; rep(i,N-1) if(d[i] != 0) seg.assign(i,1); } rep(_,Q){ int t; cin >> t; if(t == 1){ int l,r,x; cin >> l >> r >> x; l--; if(l){ d[l-1] += x; seg.assign(l-1,(d[l-1] != 0)); } if(r != N){ d[r-1] -= x; seg.assign(r-1,(d[r-1] != 0)); } }else{ int l,r; cin >> l >> r; cout << seg.sum(l-1,r-1)+1 << endl; } } }