萌新刚学OI求助,过了样例,几乎全WA

P4513 小白逛公园

兮水XiShui丶 @ 2019-01-28 21:00:19

RT\ qwq...
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>

template < class T > 
inline void read ( T &x ) {
    int s = 0 , w = 1;
    char ch = getchar ();
    while ( ch > '9' || ch < '0' ) { if ( ch == '-' ) w = -1; ch = getchar ();}
    while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ();}
    x = s * w;
    return;
}
template < typename T , typename ...Argc > 
inline void read ( T &x , Argc &...argc ) {
    read ( x );
    read ( argc... );
    return;
} 

const int INF = 998244353;
const int N = 5e5 + 10;

int n , m;              
int val[N];                 
struct Tree {
    int size;
    int lmax , rmax;
    int val , sum;
}tree[N << 2];

namespace Support {
    inline void swap ( int x , int y ) {
        int t = x;
        x = y;
        y = t;
    }
    inline int max ( int x , int y ) {
        return x > y ? x : y;
    }
    inline int min ( int x , int y ) {
        return x < y ? x : y;
    }
}

using namespace Support;

#define LC ( root << 1 )
#define RC ( root << 1 | 1 )  

void Build ( int root , int start , int end ) {
    tree[root].size = end - start + 1;
    if ( start == end ) {
        tree[root].lmax = val[start];
        tree[root].rmax = val[start];
        tree[root].val = val[start];
        tree[root].sum = val[start];
        return;
    }
    int mid = ( start + end ) >> 1;
    Build ( LC , start , mid );
    Build ( RC , mid + 1 , end );
    tree[root].sum = tree[LC].sum + tree[RC].sum;
    tree[root].lmax = max ( tree[LC].lmax , tree[RC].lmax + tree[LC].sum );
    tree[root].rmax = max ( tree[RC].rmax , tree[RC].sum + tree[LC].rmax );
    tree[root].val = max ( max ( tree[RC].val , tree[LC].val ) , tree[LC].rmax + tree[RC].lmax ); 
    return;
}              
void update ( int root , int start , int end , int pos , int val ) {
    if ( pos > end || pos < start ) 
        return; 
    if ( start == end ) {
        if ( start == pos ) {
            tree[root].val = val;
            tree[root].lmax = val;
            tree[root].rmax = val;
            tree[root].sum = val;
        }
        return;
    }
    int mid = ( start + end ) >> 1;
    update ( LC , start , mid , pos , val );
    update ( RC , mid + 1 , end , pos , val );
    tree[root].sum = tree[LC].sum + tree[RC].sum;
    tree[root].lmax = max ( tree[LC].lmax , tree[RC].lmax + tree[LC].sum );
    tree[root].rmax = max ( tree[RC].rmax , tree[RC].sum + tree[LC].rmax );
    tree[root].val = max ( max ( tree[RC].val , tree[LC].val ) , tree[LC].rmax + tree[RC].lmax ); 
    return;
}   
Tree check ( int root , int nstart , int nend , int qstart , int qend ) {
    Tree ne;
    ne.lmax = ne.rmax = ne.sum = ne.val = -INF;
    if ( qstart > nend || qend < nstart ) return ne;
    if ( qstart <= nstart && qend >= nend ) return tree[root];
    int mid = ( nstart + nend ) >> 1;
    Tree x = check ( LC , nstart , mid , qstart , qend )  , y = check ( RC , mid + 1 , nend , qstart , qend );
    ne.sum = x.sum + y.sum;
    ne.lmax = max ( x.lmax , y.lmax + x.sum );
    ne.rmax = max ( y.rmax , x.rmax + y.sum );
    ne.val = max ( max ( x.val , y.val ) , x.rmax + y.lmax );
    return ne;
}

int main ( void ) {
    read ( n , m );
    for ( int i = 1 ; i <= n ; i++ ) 
        read ( val[i] );
    Build ( 1 , 1 , n );
    for ( int i = 1 ; i <= m ; i++ ) {
        int opts;
        read ( opts );
        if ( opts == 1 ) {
            int l , r;
            read ( l , r );
            if ( l > r ) 
                swap ( l ,r );
            printf ( "%d\n" , check ( 1 , 1 , n , l , r ).val );
            continue;
        }
        else if ( opts == 2 ) {
            int p , s;
            read ( p , s );
            update ( 1 , 1 , n , p , s );
            continue;
        }
    }
    return 0;
}

by whiteqwq @ 2019-01-28 21:05:51

刚学OI都是怪物系列


by 紬文德斯 @ 2019-01-28 21:06:38

orz我学了这么久还是蓝色的

人比人气死人啊


by memset0 @ 2019-01-28 21:09:14

@紬文德斯 您也不看看注册日期


by wwz20050323 @ 2019-01-28 21:11:34

哇,memset大佬酱紫了!


by 兮水XiShui丶 @ 2019-01-28 21:12:09

@memset0 @Irressey @浅蓝色 大佬们帮我看看鸭qwq


by 紬文德斯 @ 2019-01-28 21:12:09

这倒也是=-=(逃


by Sai0511 @ 2019-01-28 21:15:06

@Kirito_Rivaille 你这个update函数写的不对啊。。


by Sai0511 @ 2019-01-28 21:17:07

抱歉,看错了...,你这个check函数不对啊,要分三段讨论


by _LostForest丶迷森 @ 2019-01-28 21:37:30

@Sai_0511 他这么写没影响的吧...


by 兮水XiShui丶 @ 2019-01-28 21:40:00

@Irressey @星小雨 @memset0 没人帮帮我嘛


| 下一页