QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684552#9529. Farm Managementhz666WA 3ms18220kbC++232.2kb2024-10-28 14:20:282024-10-28 14:20:28

Judging History

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

  • [2024-10-28 14:20:28]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:18220kb
  • [2024-10-28 14:20:28]
  • 提交

answer

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

#define endl '\n'
using i64 = long long;
using arr = array<int, 3>;

const int N = 1e6 + 10;
const int R = 1e6;
struct segtree {
i64 tree[N << 2];
void update(int pos, i64 k, int l = 1, int r = R, int p = 1) {
    if (l == r) {
        tree[p] += k;
        return;
    }
    int mid = l + r >> 1;
    if (mid >= pos) {
        update(pos, k, l, mid, p << 1);
    } else {
        update(pos, k, mid + 1, r, p << 1 | 1);
    }
    tree[p] = tree[p << 1] + tree[p << 1 | 1];
}
i64 query(int l, int r, int nl = 1, int nr = R, int p = 1) {
    if (l <= nl && r >= nr) {
        return tree[p];
    }
    int mid = nl + nr >> 1;
    i64 ans = 0;
    if (mid >= l) {
        ans += query(l, r, nl, mid, p << 1);
    }
    if (mid < r) {
        ans += query(l, r, mid + 1, nr, p << 1 | 1);
    }
    return ans;
}
int Query(int l, int r, int k, int nl = 1, int nr = R, int p = 1) {
    if (tree[p] >= k) {
        return l;
    }
    int mid = nl + nr >> 1;
    if (tree[p << 1 | 1] >= k) {
        return Query(l, r, k - tree[p << 1 | 1], nl, mid, p << 1);
    } else {
        return Query(l, r, k, mid + 1, nr, p << 1 | 1);
    }
}
}Tw, Tsum;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    int now = m;
    i64 Sum = 0;
    vector<arr> v(n);
    for (auto &[w, l, r] : v) {
        cin >> w >> l >> r;
        now -= l;
        Sum += 1LL * w * l;
        Tw.update(w, 1LL * (r - l) * w);
        Tsum.update(w, r - l);
    }
    // cerr << now << " " << Sum << endl;
    i64 ans = 0, sum = 0;
    for (auto &[w, l, r] : v) {
        now += l;
        sum = Sum - 1LL * w * l;
        // cerr << now << " " << sum << endl;
        int x = Tsum.query(w + 1, R);
        if (x >= now) {
            int xx = Tsum.Query(w + 1, R, now);
            sum += Tw.query(xx, R) + 1LL * (now - Tsum.query(xx, R)) * (xx - 1);
        } else {
            sum += Tw.query(w + 1, R) + 1LL * (now - x) * w;
        }
        // cerr << sum << endl;
        ans = max(ans, sum);
        now -= l;
    }
    cout << ans << endl;
    return 0;
}

詳細信息

Test #1:

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

input:

5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5

output:

109

result:

ok single line: '109'

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 18220kb

input:

12 62
503792 9 10
607358 1 3
600501 10 10
33249 4 4
774438 6 6
197692 3 6
495807 8 8
790225 5 9
77272 3 8
494819 4 9
894779 3 9
306279 5 6

output:

44007019

result:

wrong answer 1st lines differ - expected: '35204500', found: '44007019'