QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#382838#5069. VacationhhoppitreeCompile Error//C++149.9kb2024-04-08 19:41:312024-04-08 19:41:31

Judging History

你现在查看的是最新测评结果

  • [2024-04-08 19:41:31]
  • 评测
  • [2024-04-08 19:41:31]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e6 + 5;

long long States[N * 20], *nowState = States;

inline long long* myMalloc(int sz)
{
    long long *sta = nowState;
    nowState += sz;
    return sta;
}

char I[40000050], *J = I, O[8000050], *o = O;

inline int read()
{
    unsigned int x = 0;
    bool zf = 0;
    while ((*J < 48 || 57 < *J) && (*J) != '-') ++J;
    ((*J++ == '-') ? (zf = 1) : x = *(J - 1) ^ 48);
    while (47 < *J && *J < 58) x = (x << 1) + (x << 3) + (*J++ ^ 48);
    return (zf ? -(int)x : x);
}

inline void print(unsigned long long x)
{
    static unsigned int S[16], T = 0, y;
    do y = x / 10, S[T++] = x - y * 10; while(x = y);
    while (T) *o++ = S[--T] ^ 48;
}

int n, m, C, a[N];

namespace SEG1
{
    typedef long long LL;
    typedef tuple<LL, LL, LL, LL> dt;
    int sz;
    dt z[1 << 22];

    inline dt operator + (dt x, dt y)
    {
        auto [a, b, c, d] = x;
		auto [e, f, g, h] = y;
        return {a + e, max({b, f, d + g}), max(c, a + g), max(h, e + d)};
    }

    inline void build()
    {
        sz = 1;
        while (sz <= n + 1) {
            sz <<= 1;
        }
        for (int i = 1; i <= n; ++i) {
            z[i + sz] = {a[i], max(a[i], 0), max(a[i], 0), max(a[i], 0)};
        }
        for (int i = (n + sz) >> 1; i; --i) {
            z[i] = z[i << 1] + z[i << 1 | 1];
        }
        return;
    }

    inline void modify(int x)
    {
        z[x + sz] = {a[x], max(a[x], 0), max(a[x], 0), max(a[x], 0)};
        x += sz;
        while (x >>= 1) {
            z[x] = z[x << 1] + z[x << 1 | 1];
        }
        return;
    }

    inline long long query(int L, int R)
    {
        dt rL = {0, 0, 0, 0}, rR = {0, 0, 0, 0};
        for (L += sz - 1, R += sz + 1; L ^ R ^ 1; L >>= 1, R >>= 1) {
            (!(L & 1)) && (rL = rL + z[L ^ 1], 0);
            (R & 1) && (rR = z[R ^ 1] + rR, 0);
        }
        auto [A, B, C, D] = rL + rR;
        return B;
    }
}

int bl;
long long glo1[N], glo2[N];

namespace SEG2
{
    int n, sz;
    long long mx[1 << 22];

    inline void build()
    {
        n = bl - 2, sz = 1;
        while (sz <= n + 1) {
            sz <<= 1;
        }
        for (int i = 1; i <= n; ++i) {
            mx[i + sz] = max(glo1[i], glo2[i]);
        }
        for (int i = (n + sz) >> 1; i; --i) {
            mx[i] = max(mx[i << 1], mx[i << 1 | 1]);
        }
        return;
    }

    inline void modify(int x)
    {
        mx[x + sz] = max(glo1[x], glo2[x]);
        x += sz;
        while (x >>= 1) {
            mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
        }
        return;
    }

    inline long long query(int L, int R)
    {
        long long res = 0;
        for (L += sz - 1, R += sz + 1; L ^ R ^ 1; L >>= 1, R >>= 1) {
            (!(L & 1)) && (res = max(res, mx[L ^ 1]));
            ((R & 1)) && (res = max(res, mx[R ^ 1]));
        }
        return res;
    }
}

long long Sa[N], Sb[N];

inline tuple<long long, long long, long long> operator + (tuple<long long, long long, long long> x, tuple<long long, long long, long long> y);

struct DS
{
    int len;

    typedef long long LL;
    LL *MxA, *MxB, *LazyA, *LazyB, *S;

    friend inline tuple<LL, LL, LL> operator + (tuple<LL, LL, LL> x, tuple<LL, LL, LL> y)
    {
        long long A, B, C, D, E, F;
        tie(A, B, C) = x, tie(D, E, F) = y;
        return {max(A, D), max(B, E), max({C, F, B + D})};
    }

    void build(int k, int l, int r)
    {
        if (l == r) {
            MxA[k] = Sa[l];
            MxB[k] = Sb[l];
            S[k] = -1e18;
            return;
        }
        int mid = (l + r) >> 1;
        build(k << 1, l, mid);
        build(k << 1 | 1, mid + 1, r);
        tie(MxA[k], MxB[k], S[k]) = tuple<LL, LL, LL>(MxA[k << 1], MxB[k << 1], S[k << 1]) +
                                    tuple<LL, LL, LL>(MxA[k << 1 | 1], MxB[k << 1 | 1], S[k << 1 | 1]);
        return;
    }

    inline void Build()
    {
        int t = 2 * len, z = 1;
        while (z < t) {
            z <<= 1;
        }
        MxA = myMalloc(z + 1);
        MxB = myMalloc(z + 1);
        LazyA = myMalloc(z + 1);
        LazyB = myMalloc(z + 1);
        S = myMalloc(z + 1);
        build(1, 1, len);
        return;
    }

    tuple<LL, LL, LL> query(int k, int l, int r, int x, int y)
    {
        if (l >= x && r <= y) {
            return {MxA[k], MxB[k], S[k]};
        }
        pushdown(k);
        int mid = (l + r) >> 1;
        if (mid >= y) {
            return query(k << 1, l, mid, x, y);
        }
        if (mid < x) {
            return query(k << 1 | 1, mid + 1, r, x, y);
        }
        return query(k << 1, l, mid, x, y) + query(k << 1 | 1, mid + 1, r, x, y);
    }

    inline void addTagA(int k, int x)
    {
        LazyA[k] += x;
        MxA[k] += x;
        S[k] += x;
        return;
    }

    inline void addTagB(int k, int x)
    {
        LazyB[k] += x;
        MxB[k] += x;
        S[k] += x;
        return;
    }

    inline void pushdown(int k)
    {
        if (LazyA[k]) {
            addTagA(k << 1, LazyA[k]);
            addTagA(k << 1 | 1, LazyA[k]);
            LazyA[k] = 0;
        }
        if (LazyB[k]) {
            addTagB(k << 1, LazyB[k]);
            addTagB(k << 1 | 1, LazyB[k]);
            LazyB[k] = 0;
        }
        return;
    }

    void modifyA(int k, int l, int r, int x, int y)
    {
        if (r <= x) {
            addTagA(k, y);
            return;
        }
        if (l > x) {
            return;
        }
        pushdown(k);
        int mid = (l + r) >> 1;
        modifyA(k << 1, l, mid, x, y);
        modifyA(k << 1 | 1, mid + 1, r, x, y);
        tie(MxA[k], MxB[k], S[k]) = tuple<LL, LL, LL>(MxA[k << 1], MxB[k << 1], S[k << 1]) +
                                    tuple<LL, LL, LL>(MxA[k << 1 | 1], MxB[k << 1 | 1], S[k << 1 | 1]);
        return;
    }

    void modifyB(int k, int l, int r, int x, int y)
    {
        if (l >= x) {
            addTagB(k, y);
            return;
        }
        if (r < x) {
            return;
        }
        pushdown(k);
        int mid = (l + r) >> 1;
        modifyB(k << 1, l, mid, x, y);
        modifyB(k << 1 | 1, mid + 1, r, x, y);
        tie(MxA[k], MxB[k], S[k]) = tuple<LL, LL, LL>(MxA[k << 1], MxB[k << 1], S[k << 1]) +
                                    tuple<LL, LL, LL>(MxA[k << 1 | 1], MxB[k << 1 | 1], S[k << 1 | 1]);
        return;
    }

    inline void modify(int type, int x, int y)
    {
        if (!type) {
            modifyA(1, 1, len, x, y);
        } else {
            modifyB(1, 1, len, x, y);
        }
        return;
    }
} SEG3[N];

inline long long calc(int wh, int L = 0, int R = 0)
{
    if (!L) {
        return SEG3[wh].S[1];
    }
    L -= (wh - 1) * C, R -= (wh - 1) * C;
    long long A, B, C;
    tie(A, B, C) = SEG3[wh].query(1, 1, SEG3[wh].len, L, R);
    return C;
}

signed main()
{
    fread(I, 1, 40000038, stdin);
    n = read(), m = read(), C = read();
    bl = (n - 1) / C + 1;
    for (int i = 1; i <= n; ++i) {
        a[i] = read();
    }
    SEG1::build();
    for (int i = 2; i <= bl - 1; ++i) {
        long long s = 0, mx = 0;
        for (int j = (i - 1) * C + 1; j <= i * C && j <= n; ++j) {
            mx = max(mx, s = max(s, 0ll) + a[j]);
        }
        glo1[i] = mx;
    }
    for (int i = 1; i <= bl - 1; ++i) {
        SEG3[i].len = min((i + 1) * C, n) - i * C;
        for (int j = C; j; --j) {
            Sa[j] = Sa[j + 1] + a[j + (i - 1) * C];
        }
        for (int j = 1; j <= SEG3[i].len; ++j) {
            Sb[j] = Sb[j - 1] + a[j + i * C];
        }
        SEG3[i].Build();
    }
    for (int i = 2; i <= bl - 2; ++i) {
        glo2[i] = calc(i);
    }
    SEG2::build();
    while (m--) {
        int opt = read(), L = read(), R = read();
        if (opt == 1) {
            if (a[L] == R) {
                continue;
            }
            int D = R - a[L];
            a[L] = R;
            SEG1::modify(L);
            int bel = (L - 1) / C + 1;
            long long flg = max(glo1[bel], glo2[bel]);
            if (bel >= 2 && bel <= bl - 1) {
                glo1[bel] = SEG1::query((bel - 1) * C + 1, bel * C);
            }
            if (bel >= 2) {
                SEG3[bel - 1].modify(1, L - (bel - 1) * C, D);
            }
            if (bel <= bl - 1) {
                SEG3[bel].modify(0, L - (bel - 1) * C, D);
            }
            if (bel >= 3) {
                int tv = max(glo1[bel - 1], glo2[bel - 1]);
                glo2[bel - 1] = calc(bel - 1);
                if (max(glo1[bel - 1], glo2[bel - 1]) != tv && bel <= bl - 1) {
                    SEG2::modify(bel - 1);
                }
            }
            if (bel >= 2 && bel <= bl - 2) {
                glo2[bel] = calc(bel);
            }
            if (bel >= 2 && bel <= bl - 2 && flg != max(glo1[bel], glo2[bel])) {
                SEG2::modify(bel);
            }
        } else {
            if (R - L + 1 <= C) {
                print(SEG1::query(L, R));
                *o++ = '\n';
                continue;
            }
            int bel = (L - 1) / C + 1, ber = (R - 1) / C + 1;
            long long res = (bel + 2 >= ber ? 0ll : SEG2::query(bel + 1, ber - 2));
            if (bel + 1 != ber) {
                res = max(res, glo1[ber - 1]);
            }
            res = max({res, SEG1::query(L, L + C - 1), SEG1::query(R - C + 1, R)});
            if (ber == bel + 1) {
                res = max(res, calc(bel, L, R - C));
            } else {
                res = max({res, calc(bel, L, bel * C), calc(ber - 1, (ber - 2) * C + 1, R - C)});
            }
            print(res);
            *o++ = '\n';
        }
    }
    fwrite(O, 1, o - O, stdout);
    return 0;
}

詳細信息

answer.code: In function ‘SEG1::dt SEG1::operator+(dt, dt)’:
answer.code:47:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   47 |         auto [a, b, c, d] = x;
      |              ^
answer.code:48:22: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   48 |                 auto [e, f, g, h] = y;
      |                      ^
answer.code: In function ‘void SEG1::build()’:
answer.code:59:35: error: no matching function for call to ‘max(long long int&, int)’
   59 |             z[i + sz] = {a[i], max(a[i], 0), max(a[i], 0), max(a[i], 0)};
      |                                ~~~^~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
answer.code:59:35: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’)
   59 |             z[i + sz] = {a[i], max(a[i], 0), max(a[i], 0), max(a[i], 0)};
      |                                ~~~^~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
answer.code:59:35: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’)
   59 |             z[i + sz] = {a[i], max(a[i], 0), max(a[i], 0), max(a[i], 0)};
      |                                ~~~^~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
answer.code:59:35: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’
   59 |             z[i + sz] = {a[i], max(a[i], 0), max(a[i], 0), max(a[i], 0)};
      |                                ~~~^~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
answer.code:59:35: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’
   59 |             z[i + sz] = {a[i], max(a[i], 0), max(a[i], 0), max(a[i], 0)};
      |                                ~~~^~~~~~~~~
answer.code:59:49: error: no matching function for call to ‘max(long long int&, int)’
   59 |             z[i + sz] = {a[i], max(a[i], 0), max(a[i], 0), max(a[i], 0)};
      |                                              ~~~^~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
answer.code:59:49: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’)
   59 |             z[i + sz] = {a[i], max(a[i], 0), max(a[i], 0), max(a[i], 0)};
      |                                              ~~~^~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
answer.code:59:49: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’)
   59 |             z[i + sz] = {a[i], max(a[i], 0), max(a[i], 0), max(a[i], 0)};
      |                                              ~~~^~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
answer.code:59:49: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’
   59 |             z[i + sz] = {a[i], max(a[i], 0), max(a[i], 0)...