注意:
数据被加强了!并非正解!
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define SET0(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DWN(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll;
inline int read()
{
register int x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}
#define IT set<node>::iterator
int n,m,op;
struct node{
int l,r;
mutable bool v;
node(int L,int R=-1,bool V=0):l(L),r(R),v(V){}
bool operator<(const node &o)const{
return l<o.l;
}
};
set<node>s;
IT split(int p){
IT it=s.lower_bound(node(p));
if(it->l==p && it!=s.end()) return it;
it--;
int L=it->l; int R=it->r; bool V=it->v;
s.erase(it);
s.insert(node(L,p-1,V));
return s.insert(node(p,R,V)).first;
}
void assign(int l,int r,bool v){
IT itr=split(r+1); IT itl=split(l);
s.erase(itl,itr);
s.insert(node(l,r,v));
}
void change(int l,int r){
IT itr=split(r+1); IT itl=split(l);
for(;itl!=itr;itl++){
itl->v=!itl->v;
}
}
int sum(int l,int r){
IT itr=split(r+1); IT itl=split(l);
int res=0;
for(;itl!=itr;itl++){
if(itl->v) res+=itl->r-itl->l+1;
}
return res;
}
int cal(int l,int r){
IT itr=split(r+1); IT itl=split(l);
int cnt=0;
int rec=0;
for(;itl!=itr;itl++){
if(itl->v){
cnt+=itl->r-itl->l+1;
}
else{
rec=max(rec,cnt);
cnt=0;
}
}
return max(rec,cnt);
}
int main(){
cin>>n>>m;
FOR(i,0,n-1){
bool val;
val=read();
s.insert(node(i,i,val));
}
s.insert(node(n,n,0));
//init
FOR(i,1,m){
op=read(); int l=read();int r=read();
switch (op)
{
case 0:
assign(l,r,0);
break;
case 1:
assign(l,r,1);
break;
case 2:
change(l,r);
break;
case 3:
cout<<sum(l,r)<<endl;
break;
case 4:
cout<<cal(l,r)<<endl;
break;
default:
break;
}
}
return 0;
}