#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair PII; typedef vector VI; typedef vector VVI; #define MP make_pair #define PB push_back #define inf 1000000007 #define mod 1000000007 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define int long long template class segtree { private: int n,sz,h; vector node, lazy; void eval(int k) { if(lazy[k]){ node[k] += lazy[k]; if(k < n) { lazy[k*2] += lazy[k] / 2, lazy[k*2+1] += lazy[k] / 2; } lazy[k] = 0; } } public: segtree(vector& v) : sz((int)v.size()), h(0) { n = 1; while(n < sz) n *= 2, h++; node.resize(2*n, 0), lazy.resize(2*n, 0); for(int i = 0; i < sz; i++) node[i+n] = v[i]; for(int i = n-1; i >= 1; i--) node[i] = node[2*i] + node[2*i+1]; } void range(int a, int b, T x) { a += n, b += n - 1; for(int i = h; i > 0; i--) eval(a >> i), eval(b >> i); int ta = a, tb = b++, length = 1; while(a < b){ if(a & 1) lazy[a++] += length * x; if(b & 1) lazy[--b] += length * x; a >>= 1, b >>= 1, length <<= 1; } while(ta >>= 1, tb >>= 1, ta){ if(!lazy[ta]){ eval(2*ta), eval(2*ta+1), node[ta] = node[2*ta] + node[2*ta+1]; } if(!lazy[tb]){ eval(2*tb), eval(2*tb+1), node[tb] = node[2*tb] + node[2*tb+1]; } } } T query(int a, int b) { a += n, b += n - 1; for(int i = h; i > 0; i--) eval(a >> i), eval(b >> i); b++; T res1 = 0, res2 = 0; while(a < b) { if(a & 1) eval(a), res1 += node[a++]; if(b & 1) eval(--b), res2 += node[b]; a >>= 1, b >>= 1; } return res1 + res2; } void print(){for(int i = 0; i < sz; i++) cout<> n >> q; vectora(n),b(n-1); rep(i,n)cin >> a[i]; rep(i,n-1){ if(a[i]!=a[i+1]){ b[i] = 1; } } segtreesg(a),sg2(b); rep(i,q){ int c,l,r; cin >> c >> l >> r; l--;r--; if(c==1){ int x; cin >> x; if(l!=0){ int p = sg.query(l-1,l); int q = sg.query(l,l+1); if(p==q){ sg2.range(l-1,l,1); }else if(p+x==q){ sg2.range(l-1,l,-1); } } if(r!=n-1){ int p = sg.query(r,r+1); int q = sg.query(r+1,r+2); if(p==q){ sg2.range(r,r+1,1); }else if(p+x==q){ sg2.range(r,r+1,-1); } } sg.range(l,r+1,x); }else{ cout << sg2.query(l,r)+1 << endl; } } return 0; }