代码求hack
  • 板块P1631 序列合并
  • 楼主ACtheQ
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/9/20 21:55
  • 上次更新2023/11/2 18:56:09
查看原帖
代码求hack
755689
ACtheQ楼主2023/9/20 21:55
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N],b[N];
struct Node
{
	int A,B,t;
}heap[N];
int len;
void push(int x,int a,int b)
{
	heap[++len].t=x;
	heap[len].A=a;
	heap[len].B=b;
	int i=len;
	while(i>1&&heap[i/2].t>heap[i].t)
	{
		swap(heap[i/2],heap[i]);
		i/=2;
	}
}
void pop()
{
	heap[1]=heap[len--];
	int i=1;
	while(2*i<=len)
	{
		int son=2*i;
		if(son<len&&heap[son+1].t<heap[son].t) son++;
		if(heap[son].t<heap[i].t)
		{
			swap(heap[son],heap[i]);
			i=son;
		}
		else break;
	}
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) cin>>b[i];
	for(int i=1;i<=n;i++) push(a[i]+b[1],i,1);
	for(int i=1;i<=n;i++)
	{
		cout<<heap[1].t<<" ";
		if(heap[1].B+1<=n) push(a[heap[1].A]+b[heap[1].B+1],heap[1].A,heap[1].B+1);
		pop();
	}
	return 0;
}

在洛谷A了,POJ挂了,求hack数据!

2023/9/20 21:55
加载中...