QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#46280 | #4500. Loop | miaomiaozi | AC ✓ | 191ms | 7852kb | C++17 | 1.4kb | 2022-08-28 17:49:33 | 2022-08-28 17:49:34 |
Judging History
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;
}
详细
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