QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694705#5417. Chat Programyang1WA 379ms17532kbC++142.3kb2024-10-31 18:30:072024-10-31 18:30:07

Judging History

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

  • [2024-10-31 18:30:07]
  • 评测
  • 测评结果:WA
  • 用时:379ms
  • 内存:17532kb
  • [2024-10-31 18:30:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
using i64 = long long;

void solve() {
    int n, k, m, c, d;
    cin >> n >> k >> m >> c >> d;

    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    tree<pair<int, int>, null_type, greater<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> t1;
    tree<pair<int, int>, null_type, greater<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> t2;

    for (int i = m; i <= n; i++) {
        t1.insert({ a[i], i });
    }
    for (int i = 1; i < m; i++) {
        t2.insert({ a[i] + c + (i - 1) * d, i });
    }
    auto kth1 = [&](int k) {
        auto it = t1.find_by_order(k - 1);
        if (it != t1.end()) {
            return it->first;
        }
        else {
            return -1LL;
        }
    };
    auto kth2 = [&](int k) {
        auto it = t2.find_by_order(k - 1);
        if (it != t2.end()) {
            return it->first;
        }
        else {
            return -1LL;
        }
    };

    auto rk1 = [&](int x) {
        return t1.order_of_key({ x, -1 });
    };
    auto rk2 = [&](int x) {
        return t2.order_of_key({ x, -1 });
    };

    auto check = [&](int x, int i) {
        i64 y = kth2(x) - (i - m) * d;
        int t = rk1(y) + x;
        return t;
        };

    i64 ans = 0;
    for (int i = m; i <= n; i++) {
        t1.erase({ a[i], i });
        t2.insert({ a[i] + c + (i - 1) * d, i });

        int l = 0, r = min(k, m);
        while (r - l > 1) {
            int mid = l + r >> 1;
            if (check(mid, i) >= k) r = mid;
            else l = mid;
        }
        if (check(r, i) <= k) {
            int t = k - check(r, i);
            ans = max(ans, kth1(t));
        }
        else {
            ans = max(ans, kth2(r) - (i - m) * d);
        }

        t2.erase({ a[i - m + 1] + c + (i - m) * d, i - m + 1 });
        t1.insert({ a[i - m + 1], i - m + 1 });
    }
    cout << ans << "\n";
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 4 3 1 2
1 1 4 5 1 4

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

7 3 2 4 0
1 9 1 9 8 1 0

output:

9

result:

ok 1 number(s): "9"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

8 3 5 0 0
2 0 2 2 1 2 1 8

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 379ms
memory: 17532kb

input:

200000 200000 100000 0 1000000000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: -100
Wrong Answer
time: 178ms
memory: 17060kb

input:

200000 1 100000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...

output:

0

result:

wrong answer 1st numbers differ - expected: '100001000000000', found: '0'