QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#61845#4500. LoopqinjianbinAC ✓368ms22992kbC++141.6kb2022-11-15 16:09:452022-11-15 16:09:48

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 16:09:48]
  • 评测
  • 测评结果:AC
  • 用时:368ms
  • 内存:22992kb
  • [2022-11-15 16:09:45]
  • 提交

answer

#include<cstdio>
#include<set>
#include<iostream>

#define mid ((l+r)>>1)
#define lx (x<<1)
#define rx (x<<1|1)

using namespace std;

const int maxn =300000+5;

int n,m;
int a[maxn],b[maxn];
bool flag[maxn];

int st[maxn<<2];

void build_st(int x,int l,int r)
{
	if (l==r)
	{
		st[x]=l;
	}else {
		build_st(lx,l,mid);
		build_st(rx,mid+1,r);
		if (a[st[lx]]<a[st[rx]]) st[x]=st[rx];
		else st[x]=st[lx];
	}
}

int max_st(int x,int l,int r,int L,int R)
{
	if (r<L||l>R) return 0;
	if (l>=L&&r<=R) return st[x];
	int tL=max_st(lx,l,mid,L,R);
	int tR=max_st(rx,mid+1,r,L,R);
	if (tL==0||tR==0) return tL+tR;

	if (a[tL]<a[tR]) return tR;
	else return tL;
}

void standing_by()
{
	int i;
	int L,R;
	int mx;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++) scanf("%d",&a[i]),flag[i]=false;
	build_st(1,1,n);
	for(L=1;L<=n;L=R)
	{
		mx=max_st(1,1,n,L,L+m);
		flag[mx]=true;
		R=mx+1;
		m-=(mx-L);
	}
	//for(i=1;i<=n;i++) printf("%d ",flag[i]);
	//puts("");
}

multiset<int> qhy;

void complete()
{
	int i;
	qhy.clear();
	for(i=1;i<=n;i++)
	{
		if (flag[i])
		{
			while (!qhy.empty())
			{
				auto it=qhy.end();
				it--;
				if (*it<=a[i]) break;
				printf("%d ",*it);
				qhy.erase(it);
			}
			printf("%d ",a[i]);
		}else qhy.insert(a[i]);
	}
	if (!qhy.empty())
	{
		auto it=qhy.end();
		it--;
		while (1)
		{
			printf("%d ",*it);
			if (it==qhy.begin()) break;
			it--;
		}
	}
	puts("");
}

int main()
{
	int t=1;
	scanf("%d",&t);
	for(;t;t--)
	{
		standing_by();
		complete();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 368ms
memory: 22992kb

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