QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#522523#5000. Balanced Seesaw ArrayyzkkaiWA 316ms32020kbC++204.0kb2024-08-17 00:54:112024-08-17 00:54:12

Judging History

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

  • [2024-08-17 00:54:12]
  • 评测
  • 测评结果:WA
  • 用时:316ms
  • 内存:32020kb
  • [2024-08-17 00:54:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using LL = long long;
using pii = pair<int, int>;
using pll = pair<__int128, __int128>;
#define sz(x) signed(size(x))

struct segTree {
    int l, r, mid;
    __int128 sum1 = 0, sum2 = 0, len = 0, tot = 0, tag1 = 1e18, tag2 = 1e18;
    segTree *lson = 0, *rson = 0;

    segTree(int _l, int _r) : l(_l), r(_r), mid((l + r) >> 1) {}

    void pull() {
        sum1 = lson->sum1 + rson->sum1;
        sum2 = lson->sum2 + rson->sum2;
        return;
    }

    void push() {
        if (tag2 != 1e18) {
            for (segTree* son : {lson, rson}) {
                son->sum1 = tag2 * son->len;
                son->sum2 = tag2 * son->tot;
                son->tag1 = 1e18;
                son->tag2 = tag2;
            }
        }

        if (tag1 != 1e18) {
            for (segTree* son : {lson, rson}) {
                son->sum1 += tag1 * son->len;
                son->sum2 += tag1 * son->tot; 
                if (son->tag1 == 1e18) son->tag1 = 0;
                son->tag1 += tag1;
            }
        }

        tag1 = 1e18;
        tag2 = 1e18;

        return;
    }

    void build(const vector<int>& a) {
        if (r - l == 1) {
            sum1 = a[l];
            sum2 = 1LL * a[l] * l;
            len = 1, tot = l;
            return;
        }

        lson = new segTree(l, mid);
        rson = new segTree(mid, r);
        lson->build(a);
        rson->build(a);
        pull();
        len = lson->len + rson->len;
        tot = lson->tot + rson->tot;
        return;
    }

    void add(int ql, int qr, __int128 val) {
        if (l == ql && r == qr) {
            sum1 += val * len;
            sum2 += val * tot; 
            if (tag1 == 1e18) tag1 = 0;
            tag1 += val;
            return;
        }

        push();

        if (qr <= mid)
            lson->add(ql, qr, val);
        else if (mid <= ql)
            rson->add(ql, qr, val);
        else {
            lson->add(ql, mid, val);
            rson->add(mid, qr, val);
        }

        pull();
        return;
    }

    void modify(int ql, int qr, __int128 val) {
        if (l == ql && r == qr) {
            sum1 = val * len;
            sum2 = val * tot; 
            tag1 = 1e18;
            tag2 = val;
            return;
        }

        push();

        if (qr <= mid)
            lson->modify(ql, qr, val);
        else if (mid <= ql)
            rson->modify(ql, qr, val);
        else {
            lson->modify(ql, mid, val);
            rson->modify(mid, qr, val);
        }

        pull();
        return;
    }

    pll query(int ql, int qr) {
        if (l == ql && r == qr) 
            return {sum1, sum2};

        if (qr <= mid)
            return lson->query(ql, qr);
        else if (mid <= ql)
            return rson->query(ql, qr);
        else {
            auto [x1, y1] = lson->query(ql, mid);
            auto [x2, y2] = rson->query(mid, qr);
            return {x1 + x2, y1 + y2};
        }
    }
};

inline void solve() {
    int n, q;
    cin >> n >> q;

    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    segTree *root = new segTree(1, n + 1);
    root->build(a);

    while (q--) {
        int op, ql, qr, x;
        cin >> op >> ql >> qr;

        if (op == 1) {
            cin >> x;
            root->add(ql, qr + 1, x);
        }
        else if (op == 2) {
            cin >> x;
            root->modify(ql, qr + 1, x);
        }
        else {
            auto [sum1, sum2] = root->query(ql, qr + 1);
            sum2 -= sum1 * (ql - 1);
            if (sum1 == sum2 || (sum1 != 0 && sum2 % sum1 == 0 && sum2 / sum1 >= 1 && sum2 / sum1 <= qr - ql + 1))
                cout << "Yes\n";
            else
                cout << "No\n";
        }
    }

    return;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    while (t--)
        solve();
    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

Yes
No
Yes
Yes

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 316ms
memory: 32020kb

input:

100000 451163
-18 609 -793 393 375 313 -55 -892 -446 928 -207 -390 729 -383 27 318 -400 31 -661 202 -978 212 238 -368 351 -613 -23 400 809 1000 -431 -174 -103 886 73 -150 25 820 -689 972 777 794 -36 -231 -966 632 -418 -288 -476 725 -713 -379 896 -19 -883 338 -797 937 -557 -809 -241 -539 704 44 576 -...

output:

No
Yes
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
No
No
No
N...

result:

wrong answer 22nd lines differ - expected: 'Yes', found: 'No'