珂朵莉树是个吼东西啊
这题线段树代码4k起步……珂朵莉树只要2k……
虽然因为这题数据不随机所以珂朵莉树的复杂度实际上是错的……
然而能过就行对不对……
(不过要是到时候noip我还真不敢打……毕竟CCF那机子……)
//minamoto
#include<iostream>
#include<cstdio>
#include<set>
#include<algorithm>
#define IT set<node>::iterator
using std::set;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[<<],*p1=buf,*p2=buf;
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,:;}
int read(){
#define num ch-'0'
char ch;bool flag=;int res;
while(!isdigit(ch=getc()))
(ch=='-')&&(flag=true);
for(res=num;isdigit(ch=getc());res=res*+num);
(flag)&&(res=-res);
#undef num
return res;
}
char sr[<<],z[];int C=-,Z;
inline void Ot(){fwrite(sr,,C+,stdout),C=-;}
void print(int x){
if(C><<)Ot();if(x<)sr[++C]=,x=-x;
while(z[++Z]=x%+,x/=);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=1e5+;
struct node{
int l,r;mutable bool v;
node(int L,int R=-,int V=):l(L),r(R),v(V){}
inline bool operator <(const node &b)const
{return l<b.l;}
};
set<node> s;
IT split(int pos){
IT it=s.lower_bound(node(pos));
if(it!=s.end()&&it->l==pos) return it;
--it;
int l=it->l,r=it->r;bool v=it->v;
s.erase(it),s.insert(node(l,pos-,v));
return s.insert(node(pos,r,v)).first;
}
void assign(int l,int r,int v){
IT itr=split(r+),itl=split(l);
s.erase(itl,itr),s.insert(node(l,r,v));
}
void rev(int l,int r){
IT itr=split(r+),itl=split(l);
for(;itl!=itr;++itl) itl->v^=;
}
int sum(int l,int r){
IT itr=split(r+),itl=split(l);
int res=;
for(;itl!=itr;++itl) res+=itl->v?itl->r-itl->l+:;
return res;
}
int count(int l,int r){
int res=,tmp=;IT itr=split(r+),itl=split(l);
for(;itl!=itr;++itl)
itl->v?(tmp+=itl->r-itl->l+):(cmax(res,tmp),tmp=);
return std::max(res,tmp);
}
int main(){
// freopen("testdata.in","r",stdin);
int n=read(),m=read();
for(int i=;i<n;++i) s.insert(node(i,i,read()));
s.insert(node(n,n,));
while(m--){
int op=read(),l=read(),r=read();
switch(op){
case :assign(l,r,);break;
case :assign(l,r,);break;
case :rev(l,r);break;
case :print(sum(l,r));break;
case :print(count(l,r));break;
}
}
return Ot(),;
}