如果你wa了subhack#1

P1725 琪露诺

KANO07 @ 2024-03-21 08:41:30

终点需大于n(


by 川寰boy @ 2024-03-28 21:46:56

能详细讲一下吗?谢谢


const int N = 2e5 + 10;
const int MOD = 998244353;
const int INF = 0x7fffffff;
const int Fill = 0x3f;

int n, l, r, ans = -INF;
int f[N * 2], a[N * 2];

deque<int> q;

void solve()
{
    int i, j;
    n = rd;
    l = rd, r = rd;
    for (i = 0; i <= n; i++)
    {
        a[i] = rd;
    }
    f[0] = 0;
    for (i = l; i <= n; i++)
    {
        while (!q.empty() && f[q.front()] <= f[i - l])
        {
            q.pop_front();
        }
        q.push_front(i - l);
        if (!q.empty() && q.back() <= i - r)
        {
            q.pop_back();
        }
        f[i] = f[q.back()] + a[i];
        if (i > n - r)
        {
            ans = max(ans, f[i]);
        }
        // debug(3, i, f[i], ans);
    }
    wt(ans);
}
6 2 2
0 1 -1 1 -1 1 -1

-3

这组hack过不去,求调


by Thomas_mum @ 2024-08-23 17:20:46

f$数组没附为$-INF

|