QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#880353#9986. ShioriDecember456WA 133ms6092kbC++175.9kb2025-02-03 09:04:042025-02-03 09:04:04

Judging History

This is the latest submission verdict.

  • [2025-02-03 09:04:04]
  • Judged
  • Verdict: WA
  • Time: 133ms
  • Memory: 6092kb
  • [2025-02-03 09:04:04]
  • Submitted

answer

#include <algorithm>
#include <cstdio>
#include <queue>

#define ls(o) o << 1
#define rs(o) o << 1 | 1

constexpr int MAXN = 500000 + 2;
constexpr int MAXLOGN = 18 + 2;

class Tag {
  public:
    int addVal, assignVal;

    Tag& operator +=(const Tag &rhs) {
        if (rhs.assignVal >= 0) {
            assignVal = rhs.assignVal;
            addVal = 0;
        }
        addVal += rhs.addVal;

        return *this;
    }
};

class Triple {
  public:
    int o, l, r;
};

class Node {
  public:
    int maxVal, minVal, p, len;
    long long sum;

    Node operator +(const Node &rhs) const {
        return {
          std::max(maxVal, rhs.maxVal),
          std::min(minVal, rhs.minVal),
          minVal < rhs.minVal ? p : rhs.p,
          len + rhs.len,
          sum + rhs.sum
        };
    }

    Node operator +=(const Tag &tag) {
        if (tag.assignVal >= 0) {
            maxVal = minVal =
              tag.assignVal + tag.addVal;
            sum = (long long){maxVal} * len;
        } else {
            maxVal += tag.addVal;
            minVal += tag.addVal;
            sum += (long long){tag.addVal} * len;
        }

        return *this;
    }
};

class SegmentTree {
  public:
    int n;
    Node t[MAXN << 2];
    Tag tag[MAXN << 2];

    void push(int o, const Tag &tg, int l) {
        t[o] += tg;
        tag[o] += tg;

        if (t[o].maxVal == t[o].minVal) {
            t[o].p = l;
        }
    }

    void pushDown(int o, int l, int r) {
        if (!tag[o].addVal &&
          tag[o].assignVal < 0) {
            return;
        }

        int mid = (l + r) >> 1;

        push(ls(o), tag[o], l);
        push(rs(o), tag[o], mid);

        tag[o] = {0, -1};
    }

    void pushUp(int o) {
        t[o] = t[ls(o)] + t[rs(o)];
    }

    void build(int o, int l, int r) {
        tag[o] = {0, -1};

        if (l == r) {
            scanf("%d", &t[o].maxVal);
            t[o].sum = t[o].minVal = t[o].maxVal;
            t[o].p = l;
            t[o].len = 1;

            return;
        }

        int mid = (l + r) >> 1;

        build(ls(o), l, mid);
        build(rs(o), mid + 1, r);

        pushUp(o);
    }

    void build(int _n) {
        build(1, 1, n = _n);
    }

    void update(
      int o, int l, int r,
      int x, int y, const Tag &tg
    ) {
        if (x <= l && r <= y) {
            return push(o, tg, l);
        }

        pushDown(o, l, r);
        int mid = (l + r) >> 1;

        if (x <= mid) {
            update(ls(o), l, mid, x, y, tg);
        }
        if (y > mid) {
            update(rs(o), mid + 1, r, x, y, tg);
        }

        pushUp(o);
    }

    void assign(int l, int r, int v) {
        update(1, 1, n, l, r, {0, v});
    }

    void add(int l, int r, int v) {
        update(1, 1, n, l, r, {v, -1});
    }

    Node query(int o, int l, int r, int x, int y) {
        if (x <= l && r <= y) {
            return t[o];
        }

        pushDown(o, l, r);
        int mid = (l + r) >> 1;

        if (y <= mid) {
            return query(ls(o), l, mid, x, y);
        }
        if (x > mid) {
            return query(rs(o), mid + 1, r, x, y);
        }
        return query(ls(o), l, mid, x, y)
          + query(rs(o), mid + 1, r, x, y);
    }

    Node query(int l, int r) {
        return query(1, 1, n, l, r);
    }

    int right(int x, int v) {
        static Triple stk[MAXLOGN];
        int o = 1, l = 1, r = n, top = 0;

        while (l < r) {
            pushDown(o, l, r);
            int mid = (l + r) >> 1;

            if (x > mid) {
                o = rs(o);
                l = mid + 1;
            } else {
                stk[++ top] = {rs(o), mid + 1, r};
                o = ls(o);
                r = mid;
            }
        }

        while (top) {
            o = stk[top].o;
            if (t[o].minVal < t[o].maxVal
              || t[o].minVal != v) {
                break;
            }
            top --;
        }

        if (!top) {
            return n + 1;
        }

        l = stk[top].l;
        r = stk[top].r;

        while (l < r) {
            pushDown(o, l, r);
            int mid = (l + r) >> 1;
            Node u = t[ls(o)];

            if (u.minVal < u.maxVal || u.minVal != v) {
                o = ls(o);
                r = mid;
            } else {
                o = rs(o);
                l = mid + 1;
            }
        }

        return l;
    }
} segTree;

class Info {
  public:
    int l, r, minVal, p;

    Info(int _l, int _r) {
        Node tmp = segTree.query(l = _l, r = _r);
        minVal = tmp.minVal;
        p = tmp.p;
    }

    bool operator <(const Info &rhs) const {
        return minVal > rhs.minVal;
    }
};

int main() {
    int n, m;
    scanf("%d%d", &n, &m);

    segTree.build(n);

    while (m --) {
        int op, l, r;
        scanf("%d%d%d", &op, &l, &r);

        if (op == 1) {
            int v;
            scanf("%d", &v);

            segTree.assign(l, r, v);
        }

        if (op == 2) {
            int delta = -1, p;

            std::priority_queue<Info> q;
            q.push(Info(l, r));

            while (q.size()) {
                Info iv = q.top();
                q.pop();

                if (iv.minVal > delta + 1) {
                    break;
                }
                delta = iv.minVal;

                if (iv.p > iv.l) {
                    q.push(Info(iv.l, iv.p - 1));
                }
                if ((p = segTree.right(iv.p, delta)) <= iv.r) {
                    q.push(Info(p, iv.r));
                }
            }

            if (delta >= 0) {
                segTree.add(l, r, delta + 1);
            }
        }

        if (op == 3) {
            printf("%lld\n", segTree.query(l, r).sum);
        }
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5968kb

input:

5 8
0 7 2 1 0
1 2 4 0
2 1 3
2 3 4
3 1 3
1 2 3 4
3 1 4
2 1 5
3 2 5

output:

5
11
22

result:

ok 3 number(s): "5 11 22"

Test #2:

score: 0
Accepted
time: 0ms
memory: 6092kb

input:

1 1
0
1 1 1 0

output:


result:

ok 0 number(s): ""

Test #3:

score: -100
Wrong Answer
time: 133ms
memory: 6092kb

input:

10 500000
0 0 0 0 0 0 0 0 0 0
3 2 9
2 4 10
2 2 7
2 7 9
3 1 1
3 5 8
1 5 10 0
3 1 9
3 5 9
2 2 4
1 2 4 0
2 5 6
3 8 8
1 4 6 0
1 6 6 0
2 4 10
3 1 9
3 5 7
1 4 10 0
3 6 9
3 2 6
2 1 8
1 5 9 0
3 7 8
3 4 8
2 4 8
2 5 8
2 1 9
2 3 8
1 5 10 0
2 4 8
3 1 6
2 1 4
2 3 7
3 4 10
1 4 6 0
1 1 6 0
2 3 7
1 1 1 0
2 1 10
1 5...

output:

0
0
10
7
0
0
6
3
0
0
0
1
25
12
4
0
0
0
0
17
23
1
20
2
11
27
26
2
18
2
2
0
0
0
2
4
1
0
0
0
7
2
0
3
23
15
7
11
0
4
4
2
7
4
1
6
0
6
0
7
6
3
2
5
0
0
0
7
14
2
5
0
2
0
0
6
12
6
0
2
3
0
0
1
16
12
1
1
12
0
3
4
4
10
3
16
0
17
2
4
0
0
16
8
2
8
18
23
2
24
4
12
7
4
14
5
0
2
8
4
16
10
6
4
21
15
1
3
3
0
2
5
0
2
0...

result:

wrong answer 15th numbers differ - expected: '10', found: '4'