#include using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long LL; typedef pair P; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template T gcd(T a,T b){return b?gcd(b,a%b):a;} const LL mod=1000000007; const LL LINF=1LL<<60; const int INF=1<<30; int dx[]={1,0,-1,0,1,-1,1,-1}; int dy[]={0,1,0,-1,1,-1,-1,1}; static const int MAX_SIZE = 1 << 20; LL segMax[2 * MAX_SIZE - 1], segAdd[2 * MAX_SIZE - 1]; //区間[a, b)に値xを加算する. void add(int a, int b, LL x, int k = 0, int l = 0, int r = MAX_SIZE) { if (r <= a || b <= l) return; if (a <= l && r <= b){ segAdd[k] += x; return; } add(a, b, x, k * 2 + 1, l, (l + r) / 2); add(a, b, x, k * 2 + 2, (l + r) / 2, r); segMax[k] = max(segMax[k * 2 + 1] + segAdd[k * 2 + 1], segMax[k * 2 + 2] + segAdd[k * 2 + 2]); } LL getMax(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE) { if (r <= a || b <= l) return 0; if (a <= l && r <= b) return (segMax[k] + segAdd[k]); LL left = getMax(a, b, k * 2 + 1, l, (l + r) / 2); LL right = getMax(a, b, k * 2 + 2, (l + r) / 2, r); return (max(left, right) + segAdd[k]); } template< typename T > struct BinaryIndexedTree{ //0-indexed vector< T > bit; BinaryIndexedTree(int sz){ bit.assign(sz, 0); } //[0,k)までの総和を返す T sum(int k){ T ret = 0; for (--k; k >= 0; k = (k&(k+1))-1) ret += bit[k]; return ret; } //[l,r)の総和を返す T sum(int l, int r){ return sum(r) - sum(l); } //kにx加算する void add(int k, T x){ for (; k < bit.size(); k |= k+1) bit[k] += x; } }; int main(){ int n,q;cin >> n >> q; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; add(i,i+1,a[i]); } BinaryIndexedTree bit(n-1); for (int i = 0; i < n-1; i++) { if(a[i] != a[i+1]) bit.add(i, 1); } while(q--){ int t;cin >> t; if(t == 1){ int l,r;LL x; cin >> l >> r >> x; l--; add(l, r, x); if(l){ if(getMax(l-1,l) != getMax(l,l+1)) bit.add(l-1, 1 - bit.sum(l-1,l)); else bit.add(l-1,- bit.sum(l-1,l)); } if(r < n){ if(getMax(r-1,r) != getMax(r,r+1)) bit.add(r-1, 1 - bit.sum(r-1,r)); else bit.add(r-1,- bit.sum(r-1,r)); } } else{ int l,r;cin >> l >> r; l--,r--; cout << 1 + bit.sum(l, r) << endl; } } return 0; }