165432025-05-06 17:54:30algoproTornyokcpp17Time limit exceeded 28/100504ms64612 KiB
// UUID: c69a65dc-1c83-45e5-bc52-fe6386a4cebe
#include <bits/stdc++.h>
using namespace std;
#define int int64_t

int32_t main() {
    cin.tie(0), ios::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> b(n), h(k);
    for (int& x : b) cin >> x;
    for (int& x : h) cin >> x;
    b.push_back(2e9);

    map<int, vector<int>> hm;
    for (int i = 0; i < k; i++) {
        hm[h[i]].push_back(i);
    }

    map<int, int> hans;
    stack<int> s;
    s.push(2e9 + 1);
    for (int x : b) {
        vector<int> todo;
        while (s.top() <= x) {
            todo.push_back(s.top());
            s.pop();
        }
        for (int i = 0; i < todo.size(); i++) {
            hans[todo[i]] = max(hans[todo[i]], i + 1);
        }
        s.push(x);
    }
    hans[0] = 0;
    hans[2e9] = 0;

    vector<int> hs, vals;
    for (auto [x, y] : hans) {
        hs.push_back(x);
        vals.push_back(y);
    }
    for (int i = 1; i < vals.size(); i++) {
        vals[i] = max(vals[i], vals[i - 1]);
    }
    for (int i = 0; i < k; i++) {
        int j = upper_bound(hs.begin(), hs.end(), h[i]) - hs.begin() - 1;
        cout << vals[j] << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base28/100
1Accepted0/01ms316 KiB
2Time limit exceeded0/0490ms58500 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms508 KiB
5Accepted6/61ms316 KiB
6Wrong answer0/61ms456 KiB
7Wrong answer0/434ms5356 KiB
8Wrong answer0/457ms9876 KiB
9Accepted8/8365ms40112 KiB
10Time limit exceeded0/8483ms64612 KiB
11Time limit exceeded0/5495ms54912 KiB
12Time limit exceeded0/5485ms52124 KiB
13Accepted5/5177ms19108 KiB
14Accepted5/5328ms44108 KiB
15Time limit exceeded0/5479ms51668 KiB
16Time limit exceeded0/5488ms63764 KiB
17Time limit exceeded0/5488ms57992 KiB
18Time limit exceeded0/5503ms58016 KiB
19Time limit exceeded0/5483ms54940 KiB
20Time limit exceeded0/5493ms57640 KiB
21Time limit exceeded0/5486ms57504 KiB
22Time limit exceeded0/5504ms59332 KiB