QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#55662#4500. LooplqhsmashAC ✓186ms9504kbC++972b2022-10-14 22:07:582022-10-14 22:07:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-14 22:07:59]
  • 评测
  • 测评结果:AC
  • 用时:186ms
  • 内存:9504kb
  • [2022-10-14 22:07:58]
  • 提交

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;
}

詳細信息

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