警示后人

P2572 [SCOI2010] 序列操作

tjr0513 @ 2023-09-19 20:17:16

如果你本地能跑但是洛谷没过编(Nothing is compiled: OUTPUT exceeds.),可能是编译时间过长

可能是结构体初始化耗时过长

struct node{
    int l=0, r=0;//可能是赋初值过于耗时
    int sum1=0;
    int mx1=0, lmx1=0, rmx1=0;
    int sum0=0;
    int mx0=0, lmx0=0, rmx0=0;
    int cov=0;
    bool lz=0;
    node friend operator + (const node& x, const node& y){
        node res;
        res.cov = -1;
        res.l = x.l; res.r = y.r;
        res.sum1 = x.sum1 + y.sum1;
        res.sum0 = x.sum0 + y.sum0;
        res.mx1 = max(x.rmx1 + y.lmx1, max(x.mx1, y.mx1));
        res.mx0 = max(x.rmx0 + y.lmx0, max(x.mx0, y.mx0));
        res.lmx1 = x.lmx1;
        res.lmx0 = x.lmx0;
        res.rmx1 = y.rmx1;
        res.rmx0 = y.rmx0;
        if (x.sum1 == x.r - x.l + 1) res.lmx1 = x.r - x.l + 1 + y.lmx1;
        if (x.sum0 == x.r - x.l + 1) res.lmx0 = x.r - x.l + 1 + y.lmx0;
        if (y.sum1 == y.r - y.l + 1) res.rmx1 = y.r - y.l + 1 + x.rmx1;
        if (y.sum0 == y.r - y.l + 1) res.rmx0 = y.r - y.l + 1 + x.rmx0;
        return res;
    }
}tree[N << 2];

可以把赋初值放到build里面


|