QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#55662 | #4500. Loop | lqhsmash | AC ✓ | 186ms | 9504kb | C++ | 972b | 2022-10-14 22:07:58 | 2022-10-14 22:07:59 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5e5 + 50;
int T = 1;
int stk[N], tp;
int n, a[N], b[N], k, cnt;
void solve () {
scanf ("%d%d", &n, &k);
cnt = 0, tp = 0;
for (int i = 1; i <= n; i ++)
scanf ("%d", &a[i]);
for (int i = 1; i <= n; i ++) {
while (tp && a[stk[tp]] < a[i] && k)
b[++ cnt] = a[stk[tp --]], k --;
stk[++ tp] = i;
}
sort (b + 1, b + cnt + 1);
vector<int> g;
for (int i = tp, j = 1; i >= 1; i --) {
for (; j <= cnt && a[stk[i]] >= b[j]; j ++)
g.push_back (b[j]);
g.push_back (a[stk[i]]);
}
for (int i = n - 1; i >= 0; i --)
printf("%d ", g[i]);
printf("\n");
}
int main () {
#ifdef LOCAL
freopen ("in.in", "r", stdin);
freopen ("out.out", "w", stdout);
#endif
scanf ("%d", &T);
while (T --) {
solve ();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 186ms
memory: 9504kb
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