QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694711#5417. Chat Programyang1WA 518ms17472kbC++142.3kb2024-10-31 18:30:492024-10-31 18:30:51

Judging History

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

  • [2024-10-31 18:30:51]
  • 评测
  • 测评结果:WA
  • 用时:518ms
  • 内存:17472kb
  • [2024-10-31 18:30:49]
  • 提交

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: 3624kb

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: 3516kb

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: 3572kb

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: 378ms
memory: 17468kb

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: 0
Accepted
time: 169ms
memory: 17472kb

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:

100001000000000

result:

ok 1 number(s): "100001000000000"

Test #6:

score: 0
Accepted
time: 79ms
memory: 17052kb

input:

200000 1 200000 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:

200001000000000

result:

ok 1 number(s): "200001000000000"

Test #7:

score: -100
Wrong Answer
time: 518ms
memory: 17064kb

input:

200000 24420 17993 881138881 700368758
231187558 519018952 260661004 740633836 931672020 155904999 647179942 13217847 779799803 382810661 242588977 708308843 309853544 225488875 389115097 588643904 644409212 704920939 231829287 39891424 881158891 341251089 486868469 808002305 629160633 317239613 771...

output:

999999979

result:

wrong answer 1st numbers differ - expected: '964474978', found: '999999979'