QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#252554#3835. OraclergnerdplayerWA 1258ms113908kbC++202.8kb2023-11-15 21:05:432023-11-15 21:05:44

Judging History

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

  • [2023-11-15 21:05:44]
  • 评测
  • 测评结果:WA
  • 用时:1258ms
  • 内存:113908kb
  • [2023-11-15 21:05:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using i64 = __int128_t;

using u64 = unsigned long long;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

struct Treap {
    Treap *lc = nullptr, *rc = nullptr;
    int sz = 1;
    i64 k = 0, b = 0;
    i64 val = 0;
    u64 w = rng();
    Treap(i64 v) : val(v) {}
};

int size(Treap *t) {
    return t ? t->sz : 0;
}

void pull(Treap *t) {
    t->sz = size(t->lc) + size(t->rc) + 1;
}

void apply(Treap *t, i64 k, i64 b) {
    if (!t) { return; }
    t->k += k;
    t->b += b;
    t->val += k * (1 + size(t->lc)) + b;
}

void push(Treap *t) {
    apply(t->lc, t->k, t->b);
    apply(t->rc, t->k, t->k * (1 + size(t->lc)) + t->b);
    t->k = t->b = 0;
}

template <typename F>
pair<Treap*, Treap*> split(Treap *t, int s, F f) {
    if (!t) { return {t, t}; }
    push(t);
    Treap *a, *b;
    if (f(t, s + size(t->lc) + 1)) {
        b = t;
        tie(a, b->lc) = split(t->lc, s, f);
    } else {
        a = t;
        tie(a->rc, b) = split(t->rc, s + size(t->lc) + 1, f);
    }
    pull(t);
    return {a, b};
}

Treap* merge(Treap *a, Treap *b) {
    if (!a) { return b; }
    if (!b) { return a; }
    push(a), push(b);
    if (a->w > b->w) {
        a->rc = merge(a->rc, b);
        pull(a);
        return a;
    } else {
        b->lc = merge(a, b->lc);
        pull(b);
        return b;
    }
}

ostream& operator<<(ostream &os, i64 n) {
    if (n == 0) { return os << 0; }
    if (n < 0) { os << '-', n = -n; }
    string s;
    while (n > 0) {
        s += '0' + n % 10;
        n /= 10;
    }
    reverse(s.begin(), s.end());
    return os << s;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int t;
    cin >> t;

    auto solve = [&]() {
        int n;
        cin >> n;

        vector<int> p(n);
        for (int i = 0; i < n; i++) {
            cin >> p[i];
        }

        int a, b;
        cin >> a >> b;

        vector<i64> func(n + 1);
        for (int i = 1; i <= n; i++) {
            func[i] = 1LL * i * i + a * i + b;
        }

        Treap *t = nullptr;

        for (auto p : p) {
            auto [t1, t2] = split(t, 0, [&](Treap *t, int s) {
                return func[s] * p >= t->val;
            });
            int s = size(t1) + 1;
            apply(t2, 2 * p, (2 * s + a - 1) * p);
            t = merge(merge(t1, new Treap (func[s] * p)), t2);
        }

        i64 ans = 0;

        for (int i = 1; i <= n; i++) {
            auto [t1, t2] = split(t, 0, [&](Treap *t, int s) {
                return s > 1;
            });
            ans += t1->val;
            t = t2;
            cout << ans << " \n"[i == n];
        }
    };

    while (t--) {
        solve();
    }
    
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1258ms
memory: 113908kb

input:

20
50000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...

output:

50000 249999 699994 1499980 2749950 4549895 6999804 10199664 14249460 19249175 25298790 32498284 40947634 50746815 61995800 74794560 89243064 105441279 123489170 143486700 165533830 189730519 216176724 244972400 276217500 310011975 346455774 385648844 427691130 472682575 520723120 571912704 62635126...

result:

wrong answer 5th lines differ - expected: '1550000 3900000 7149938 113997...542291549966 911937547292850000', found: '1550000 3900000 7149938 113997...240230027022 902210245231327056'