#include using namespace std; #define F first #define S second #define R cin>> #define Z class #define ll long long #define ln cout<<'\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) templatevoid pr(A a){cout<void pr(A a,B b){cout<void pr(A a,B b,C c){cout<void pr(A a,B b,C c,D d){cout<void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<=0&&x=0&&y P; class BIT{ public: ll n,bit[555555]; BIT(){fill(bit,bit+555555,0);} void add(ll i,ll x){ while(i<=n){ bit[i]+=x; i+=i&-i; } } ll sum(ll i){ ll s=0; while(i>0){ s+=bit[i]; i-=i&-i; } return s; } }; int N=1<<18; class StarrySkyTree{ public: ll Ma[555555],A[555555]; void init(){memset(Ma,0,sizeof(Ma)),memset(A,0,sizeof(A));} void add(int a,int b,ll x,int k=0,int l=0,int r=N) { if(r<=a||b<=l) return; if(a<=l&&r<=b){ A[k]+=x; while(k){ k=(k-1)/2; Ma[k]=max(Ma[k*2+1]+A[k*2+1],Ma[k*2+2]+A[k*2+2]); } return; } add(a,b,x,k*2+1,l,(l+r)/2); add(a,b,x,k*2+2,(l+r)/2,r); } ll getMax(int a,int b,int k=0,int l=0,int r=N) { if(r<=a||b<=l)return -LLONG_MAX;if(a<=l&&r<=b)return Ma[k]+A[k]; ll left=getMax(a,b,k*2+1,l,(l+r)/2),right=getMax(a,b,k*2+2,(l+r)/2,r); return max(left,right)+A[k]; } }; BIT b=BIT(); StarrySkyTree t; void Main() { int n,T; cin >> n >> T; int a[n]; rep(i,n) R a[i]; t.init(); b.n=n+1; rep(i,n-1) { if(a[i]!=a[i+1]) b.add(i+1,1); } rep(i,n) t.add(i,i+1,a[i]); while(T--) { int x,y,z; cin >> z >> x >> y; x--,y--; if(z==1) { if(x-1>=0) { ll xx=t.getMax(x-1,x); ll yy=t.getMax(x,x+1); if(xx!=yy) b.add(x,-1); } if(y+1> w; t.add(x,y+1,w); if(x-1>=0) { ll xx=t.getMax(x-1,x); ll yy=t.getMax(x,x+1); if(xx!=yy) b.add(x,1); } if(y+1