Submission #1331888

#TimeUsernameProblemLanguageResultExecution timeMemory
1331888kawhietStone Arranging 2 (JOI23_ho_t1)C++20
60 / 100
2094 ms14548 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    auto b = a;
    ranges::sort(b);
    b.erase(unique(b.begin(), b.end()), b.end());
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        int x = ranges::lower_bound(b, a[i]) - b.begin();
        m[x] = a[i];
        a[i] = x;
    }
    vector<int> f(n, -1);
    for (int i = 0; i < n; i++) {
        if (f[a[i]] == -1) {
            f[a[i]] = i;
        } else {
            for (int j = 0; j < b.size(); j++) {
                if (f[j] > f[a[i]]) {
                    f[j] = -1;
                }
            }
        }
    }
    vector<array<int, 2>> v;
    for (int i = 0; i < n; i++) {
        if (f[i] != -1) {
            v.push_back({f[i], m[i]});
        }
    }
    ranges::sort(v);
    int pos = 0;
    for (int i = 0; i < v.size() - 1; i++) {
        while (pos < v[i + 1][0]) {
            cout << v[i][1] << ' ';
            pos++;
        }
    }
    while (pos < n) {
        cout << v.back()[1] << ' ';
        pos++;
    }
    cout << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...