QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#603469#6435. Paimon Segment Treeucup-team3519#WA 1ms4080kbC++175.8kb2024-10-01 16:45:562024-10-01 16:45:56

Judging History

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

  • [2024-10-01 16:45:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4080kb
  • [2024-10-01 16:45:56]
  • 提交

answer

#include <bits/stdc++.h>

template <int m>
struct ModInt {
private:
    int raw_;
    using mint = ModInt;
    using i64 = int64_t;

public:
    ModInt() {
        raw_ = 0;
    }
    template <typename T>
    ModInt(const T &v) {
        raw_ = v % m;
    }
    int value() const {
        return (raw_ + m) % m;
    }
    mint &operator+=(const mint &rhs) {
        raw_ = (raw_ + rhs.raw_) % m;
        return *this;
    }
    mint &operator-=(const mint &rhs) {
        raw_ = (raw_ - rhs.raw_) % m;
        return *this;
    }
    mint &operator*=(const mint &rhs) {
        raw_ = (i64)raw_ * rhs.raw_ % m;
        return *this;
    }
    mint &operator/=(const mint &rhs) {
        raw_ = (i64)raw_ * qpow(rhs.raw_, m - 2) % m;
        return *this;
    }
    friend mint operator+(const mint &lhs, const mint &rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint &lhs, const mint &rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint &lhs, const mint &rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint &lhs, const mint &rhs) {
        return mint(lhs) /= rhs;
    }
    static constexpr int mod() {
        return m;
    }
    static constexpr int qpow(int a, int b) {
        int res = 1;
        while (b) {
            if (b & 1) {
                res = (i64)res * a % m;
            }
            a = (i64)a * a % m, b >>= 1;
        }
        return res;
    }
};

using mint = ModInt<static_cast<int>(1e9 + 7)>;
constexpr int MAXN = 5e4 + 19, MAXB = 230;

struct Chunk;
struct Single {
    mint val, acc;
    void modify(Chunk &chunk, mint d);
} single[MAXN];

struct Chunk {
    int num;
    mint sum, sqr, acc;
    mint tag_v_add;
    mint tag_p2, tag_p1, tag_p0;
    void push_down(Single *first, Single *last) {
        if (!tag_v_add.value() && !tag_p2.value() && !tag_p1.value() &&
            !tag_p0.value()) {
            return;
        }
        for (auto it = first; it != last; ++it) {
            it->acc += it->val * it->val * tag_p2 + it->val * tag_p1 + tag_p0;
            it->val += tag_v_add;
        }
        tag_v_add = 0;
        tag_p2 = tag_p1 = tag_p0 = 0;
    }
    void modify(mint d) {
        sqr += sum * d * 2 + d * d * num;
        sum += d * num;
        tag_v_add += d;
    }
    void accumulate() {
        acc += sqr;
        tag_p2 += 1;
        tag_p1 += tag_v_add * 2;
        tag_p0 += tag_v_add * tag_v_add;
    }
} chunk[MAXB];

void Single::modify(Chunk &chunk, mint d) {
    chunk.sum -= val;
    chunk.sqr -= val * val;

    val += d;

    chunk.sum += val;
    chunk.sqr += val * val;
}

struct Query {
    int l, r, id, fac;
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, m, q;
    std::cin >> n >> m >> q;

    const int B = std::max((int)sqrt(n), 10);
    std::vector<int> belong(n + 1);
    std::vector<int> chunk_L(n + 1, n + 1), chunk_R(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        belong[i] = (i - 1) / B + 1;
        chunk_L[belong[i]] = std::min(chunk_L[belong[i]], i);
        chunk_R[belong[i]] = std::max(chunk_R[belong[i]], i);
    }
    const int NB = belong[n];

    for (int i = 1; i <= n; ++i) {
        int d;
        std::cin >> d;
        single[i].modify(chunk[belong[i]], d);
    }

    std::vector<int> l(m + 1), r(m + 1), x(m + 1);
    for (int i = 1; i <= m; ++i) {
        std::cin >> l[i] >> r[i] >> x[i];
    }

    std::vector<mint> ans(q);
    std::vector<std::vector<Query>> query(m + 1);
    for (int i = 0; i < q; ++i) {
        int l, r, x, y;
        std::cin >> l >> r >> x >> y;
        if (x - 1 >= 0) {
            query[x - 1].push_back(Query{l, r, i, -1});
        }
        query[y].push_back(Query{l, r, i, 1});
    }

    auto push_down = [&](int b) {
        chunk[b].push_down(single + chunk_L[b], single + chunk_R[b] + 1);
    };
    for (int _ = 0; _ <= m; ++_) {
        if (_) {
            int L = l[_], R = r[_], X = x[_];
            if (belong[L] == belong[R]) {
                int b = belong[L];
                push_down(b);
                for (int i = L; i <= R; ++i) {
                    single[i].modify(chunk[b], X);
                }
            } else {
                int bl = belong[L], br = belong[R];
                push_down(bl);
                push_down(br);
                for (int i = bl + 1; i < br; ++i) {
                    chunk[i].modify(X);
                }
                for (int i = L; belong[i] == bl; ++i) {
                    single[i].modify(chunk[bl], X);
                }
                for (int i = R; belong[i] == br; --i) {
                    single[i].modify(chunk[br], X);
                }
            }
        }
        for (int i = 1; i <= NB; ++i) {
            chunk[i].accumulate();
        }
        for (const auto q : query[_]) {
            int L = q.l, R = q.r;
            mint res = 0;
            if (belong[L] == belong[R]) {
                int b = belong[L];
                push_down(b);
                for (int i = L; i <= R; ++i) {
                    res += single[i].acc;
                }
            } else {
                int bl = belong[L], br = belong[R];
                push_down(bl);
                push_down(br);
                for (int i = bl + 1; i < br; ++i) {
                    res += chunk[i].acc;
                }
                for (int i = L; belong[i] == bl; ++i) {
                    res += single[i].acc;
                }
                for (int i = R; belong[i] == br; --i) {
                    res += single[i].acc;
                }
            }
            ans[q.id] += res * q.fac;
        }
    }

    for (mint i : ans) {
        std::cout << i.value() << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3904kb

input:

3 1 1
8 1 6
2 3 2
2 2 0 0

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3932kb

input:

4 3 3
2 3 2 2
1 1 6
1 3 3
1 3 6
2 2 2 3
1 4 1 3
4 4 2 3

output:

180
825
8

result:

ok 3 number(s): "180 825 8"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 4080kb

input:

100 107 180
-280960553 266308104 -997644864 856103777 592874377 674379235 -946339772 641750362 642418716 -360811715 -555543246 206614021 358239245 349842656 983198973 807518446 -66612455 -980932737 109826132 -109676067 51226145 452115561 -42729559 -950621304 -87009773 714026474 375317493 693260053 -...

output:

400489222
431960052
599028187
385988900
451225715
721890631
142229431
997696691
809411650
66225912
247029353
298760339
332854566
481818234
506193781
686765345
287848172
344690576
113189826
450390031
259541617
209874249
819787321
502972649
385645083
179850996
32603218
141144218
66103316
782273785
691...

result:

wrong answer 2nd numbers differ - expected: '480617351', found: '431960052'