序列操作

确实 这个odt 好写。。只是会被对着卡掉。。。

一定记住 把 split r+1 写在l前面,,,因此re*n。。。

/*Heroes Never Die!*/
#include "iostream"
#include "cstring"
#include "cstdio"
#include "set"
#include "algorithm"
#define auto set<node>::iterator
using namespace std;
struct node{
    int l , r ;
    mutable int v ;
    node( int l , int r = -1 , int v = 0 ) : l( l ) , r( r ) , v( v ) {}
    bool operator < ( const node & x ) const {
        return x . l > l;
    }
};
set< node > S;
int n , m ;
void build( ) {
    for( int i = 0 , u ; i < n ; ++ i )
        scanf("%d",&u), S.insert( node( i , i , u ) );
}
set<node>::iterator split( int pos ) {
    auto it = S . lower_bound( node( pos ) );
    if( it != S.end() && it -> l == pos ) return it;
    -- it;
    int l = it -> l , r = it -> r , v = it -> v;
    S.erase( it ) , S.insert( node( l , pos - 1 , v ) );
    return S.insert( node( pos , r , v ) ).first;
}
void assign( int l , int r , int v ) {
    auto R = split( r + 1 ) , L = split( l ) ;
    S.erase( L , R ) , S.insert( node( l , r , v ) );
}
void reverse( int l , int r ) {
    auto R = split( r + 1 ) , L = split( l ) ;
    for( ; L != R ; ++ L ) L -> v ^= 1;
}
int count ( int l , int r ) {
    int res = 0;
    auto R = split( r + 1 ) , L = split( l ) ;
    for( ; L != R ; ++ L ) if( L -> v == 1 )
        res += L -> r - L -> l + 1;
    return res;
}
int work ( int l , int r ) {
    int cur = 0 , ans = 0;
    auto  R = split( r + 1 ) , L = split( l ) ;
    for( ; L != R ; ++ L )
        if(L -> v == 1)
            cur += ( L -> r - L -> l + 1 );
        else ans = max( ans , cur ) , cur = 0;
    return max( ans , cur );
}
int main(){
    cin >> n >> m;
    build();
    S.insert( node( n , n , 0 ) );
    for( int i = 0 , opt , u , v ; i < m ; ++ i ){
        scanf("%d%d%d" , &opt , &u , &v ) ;
        if( opt == 0 ) assign( u , v , 0 );
        else if( opt == 1 ) assign( u , v , 1 );
        else if( opt == 2 ) reverse( u , v );
        else if( opt == 3 ) printf( "%d\n" , count( u , v ) );
        else if( opt == 4) printf( "%d\n" , work( u , v ) );
    }
}