QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#525810#3998. The ProfiteerRPChe_WA 2ms11020kbC++142.2kb2024-08-20 22:58:562024-08-20 22:58:57

Judging History

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

  • [2024-08-20 22:58:57]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11020kb
  • [2024-08-20 22:58:56]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
int n, m, lim, v[N], a[N], b[N], mn[N], top;
vector<int> f[N];
typedef long long ll;
ll ans;

void create() {
    top++;
    f[top].resize(m + 1);
    for (int i = 0; i <= m; i++) {
        f[top][i] = f[top - 1][i];
    }
}
void erase() {
    top--;
}
void update(int c, int v) {
    for (int i = m; i >= c; i--) {
        f[top][i] = max(f[top][i], f[top][i - c] + v);
    }
}
bool check() {
    ll res = 0;
    for (int i = 1; i <= m; i++) {
        res += f[top][i];
    }
    return res <= 1ll * lim * m;
}
void small(int l, int r) {
    for (int i = l; i <= r; i++) {
        update(a[i], v[i]);
    }
}
void big(int l, int r) {
    for (int i = l; i <= r; i++) {
        update(b[i], v[i]);
    }
}

void divide(int l, int r, int L, int R) {
    if (l > r) return;
    create();
    int M = (L + R) >> 1;
    big(max(l, L), M);
    small(max(l, M + 1), R);
    int tl = l, tr = r, res = l - 1;
    while (tl <= tr) {
        create();
        int mid = (tl + tr) >> 1;
        big(mid, tr);
        small(tl, mid - 1);
        if (check()) {
            erase();
            small(tl, mid);
            res = mid;
            tl = mid + 1;
        } else {
            erase();
            big(mid, tr);
            tr = mid - 1;
        }
    }
    if (L == R) {
        for (int i = l; i <= res; i++) {
            mn[i] = L;
        }
        for (int i = res + 1; i <= r; i++) {
            mn[i] = n + 1;
        }
        return;
    }
    erase();
    create();
    small(M + 1, R);
    big(res + 1, min(r, L - 1));
    divide(l, res, L, M);
    erase();
    create();
    small(l, res);
    big(max(L, r + 1), M);
    divide(res + 1, r, M + 1, R);
    erase();
}

int main() {
    scanf("%d%d%d", &n, &m, &lim);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d%d", &v[i], &a[i], &b[i]);
    }
    for (int i = 0; i <= m; i++) {
        f[0].push_back(0);
    }
    divide(1, n, 1, n);
    for (int i = 1; i <= n; i++) {
        ans += n - mn[i] + 1;
    }
    printf("%lld\n", ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11020kb

input:

4 5 3
3 2 4
1 2 3
2 1 2
3 1 3

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 2ms
memory: 10944kb

input:

4 5 4
3 2 4
1 2 3
2 1 2
3 1 3

output:

3

result:

ok single line: '3'

Test #3:

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

input:

4 5 5
3 2 4
1 2 3
2 1 2
3 1 3

output:

2

result:

wrong answer 1st lines differ - expected: '7', found: '2'