QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#61928#4500. LoopqinjianbinAC ✓223ms6704kbC++17745b2022-11-15 22:58:522022-11-15 22:58:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-15 22:58:54]
  • 评测
  • 测评结果:AC
  • 用时:223ms
  • 内存:6704kb
  • [2022-11-15 22:58:52]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;

const int N = 3e5 + 10;
int st[N], top, n, k;

int main()
{
	int T; scanf("%d", &T);
	while(T--)
	{
		top = 0;
		scanf("%d%d", &n, &k);

		priority_queue<int> q;
		_for(i, 1, n)
		{
			int x; scanf("%d", &x);
			while(k && top && x > st[top])
			{
				k--;
				q.push(st[top--]);
			}
			st[++top] = x;
		}

		_for(i, 1, top)
		{
			while(!q.empty() && q.top() > st[i])
			{
				printf("%d ", q.top());
				q.pop();
			}
			printf("%d ", st[i]);
		}
		while(!q.empty()) 
		{
			printf("%d ", q.top());
			q.pop();
		}
		puts("");
	}
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 223ms
memory: 6704kb

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