QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#670648#5417. Chat ProgramyellTL 0ms3632kbC++201.8kb2024-10-23 22:45:042024-10-23 22:45:29

Judging History

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

  • [2024-10-23 22:45:29]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3632kb
  • [2024-10-23 22:45:04]
  • 提交

answer

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

template <typename T>
struct Fenwick {
    int n;
    vector<T> a;

    Fenwick(int n) { init(n); }

    void init(int n) {
        this->n = n;
        a.assign(n + 1, 0);
    }

    void modify(int x, T s) {
        for (; x; x -= x & (-x)) {
            a[x] += s;
        }
    }

    T query(T x) {
        T ans = 0;
        for (x; x <= n; x += x & (-x)) {
            ans += a[x];
        }
        return ans;
    }

    T query(int l, int r) { return query(r) - query(l); }
};

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];
    }
    auto p = a;
    sort(p.begin() + 1, p.end());
    Fenwick<int> t(n + 1);
    for (int i = 1; i <= n; i++) {
        int idx = lower_bound(p.begin(), p.end(), a[i]) - p.begin();
        t.modify(idx, 1);
    }

    auto check = [&](LL x) -> bool {
        int mx = 0;
        for (int i = 1; i + m - 1 <= n; i++) {
            int j = i + m - 1;
            int idx = lower_bound(p.begin(), p.end(), x) - p.begin();
            int cnt = t.query(idx);
            for (int x = i; x <= j; x++) {
                if (a[x] + 1LL * d * (x - i) > x) {
                    cnt++;
                }
            }
            mx = max(mx, cnt);
        }
        return mx >= k;
    };

    LL l = 0, r = 1e18;
    while (l < r) {
        LL mid = (l + r + 1) / 2;
        if (check(mid)) {
            l = mid;
        } else {
            r = mid - 1;
        }
    }
    cout << l << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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: -100
Time Limit Exceeded

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:


result: