QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#46280#4500. LoopmiaomiaoziAC ✓191ms7852kbC++171.4kb2022-08-28 17:49:332022-08-28 17:49:34

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-28 17:49:34]
  • 评测
  • 测评结果:AC
  • 用时:191ms
  • 内存:7852kb
  • [2022-08-28 17:49:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// https://space.bilibili.com/672346917

#ifndef LOCAL
#define LOG(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long LL;
typedef pair <int, int> PII;

constexpr int inf = 0x3f3f3f3f;
constexpr double EPS = 1e-8;
const double PI = acos(-1);

int multi_cases = 1;

void A_SOUL_AvA () {
    int n, k;
    cin >> n >> k;

    vector <int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    priority_queue <int> q;
    for (int i = 1; i <= n; i++) {
        if (q.size() < k) {
            q.push(a[i]);
            a[i] = -1;
        } else if (q.size() >= k && q.top() > a[i]) {
            int f = q.top();
            q.pop();
            q.push(a[i]);
            a[i] = f;
        }
    }

    for (int i = 1; i <= n; i++) {
        if (a[i] != -1) {
            cout << a[i] << " ";
        }
    }
    while (q.size()) {
        int x = q.top();
        q.pop();
        cout << x << " ";
    }
    cout << endl;
}

int main () {
    cin.tie(nullptr)->sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int T = 1;
    for (multi_cases && cin >> T; T; T--) {
        A_SOUL_AvA ();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 191ms
memory: 7852kb

input:

100
300000 300000
1 1 300000 153456 153456 1 153456 153456 300000 1 300000 1 300000 300000 300000 1 300000 300000 300000 1 300000 300000 300000 300000 300000 1 300000 153456 300000 1 153456 153456 1 300000 153456 300000 300000 1 300000 1 1 153456 153456 300000 153456 153456 153456 153456 1 300000 30...

output:

300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000...

result:

ok 100 lines