为什么第7个点过不啊

P1253 扶苏的问题

NCUJACK @ 2024-02-05 16:08:56

发不了图片qaq

#include <bits/stdc++.h>
#define int long long
#define lc p << 1
#define rc (p << 1) | 1
using namespace std;
const int cst = 1e6 + 10, inf = 1e10 + 10;
int n, q;
int w[cst];
struct node
{
    int l, r, add, tag, Max, t;
} tr[cst * 4];
void pushUp(int p)
{
    tr[p].Max = max(tr[lc].Max, tr[rc].Max);
}
void build(int p, int l, int r)
{
    tr[p] = {l, r, 0, 0, w[l], 0};
    if (l == r)
        return;
    int m = (l + r) / 2;
    build(lc, l, m);
    build(rc, m + 1, r);
    pushUp(p);
}
void pushDown(int p)
{
    if (tr[p].l != tr[p].r)
    {
        if (tr[p].tag != 0)
        {
            tr[lc].Max = tr[rc].Max = tr[p].t;
            tr[lc].add = tr[rc].add = 0;
            tr[lc].tag = 1;
            tr[rc].tag = 1;
            tr[p].tag = 0;
            tr[lc].t = tr[p].t;
            tr[rc].t = tr[p].t;
            tr[p].t = 0;
        }
        tr[lc].Max += tr[p].add;
        tr[rc].Max += tr[p].add;
        tr[lc].add += tr[p].add;
        tr[rc].add += tr[p].add;
        tr[p].add = 0;
    }
}
void change1(int p, int x, int y, int k)
{
    if (x > tr[p].r || tr[p].l > y)
        return;
    if (x <= tr[p].l && tr[p].r <= y)
    {
        tr[p].tag = 1;
        tr[p].t = k;
        tr[p].add = 0;
        tr[p].Max = k;
        return;
    }
    pushDown(p);
    change1(lc, x, y, k);
    change1(rc, x, y, k);
    pushUp(p);
}
void change2(int p, int x, int y, int k)
{
    if (tr[p].l > y || tr[p].r < x)
        return;
    if (x <= tr[p].l && tr[p].r <= y)
    {
        tr[p].add += k;
        tr[p].Max += k;
        return;
    }
    pushDown(p);
    change2(lc, x, y, k);
    change2(rc, x, y, k);
    pushUp(p);
}
int query(int p, int x, int y)
{
    if (x > tr[p].r || y < tr[p].l)
        return -inf;
    if (x <= tr[p].l && tr[p].r <= y)
    {
        return tr[p].Max;
    }
    pushDown(p);
    return max(query(lc, x, y), query(rc, x, y));
}
inline int readint()
{
    int a = 0, c = getchar(), f = 1;
    for (; !isdigit(c); c = getchar())
        if (c == '-')
            f = -1;
    for (; isdigit(c); c = getchar())
        a = (a << 3) + (a << 1) + (c ^ 48);
    return a * f;
}
inline void print(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        print(x / 10);
    putchar(x % 10 + '0');
}
signed main()
{
    n = readint(), q = readint();
    for (int i = 1; i <= n; i++)
    {
        w[i] = readint();
    }
    build(1, 1, n);
    while (q--)
    {
        int op = readint(), l = readint(), r = readint(), x;
        if (op == 1)
        {
            x = readint();
            change1(1, l, r, x);
        }
        else if (op == 2)
        {
            x = readint();
            change2(1, l, r, x);
        }
        else
        {
            print(query(1, l, r));
            puts("");
        }
    }
    return 0;
}

by NCUJACK @ 2024-02-05 16:11:40

能发了qaq


by NCUJACK @ 2024-02-05 16:12:10

是第六个点www


by NCUJACK @ 2024-02-06 15:27:04

过了www


|