萌新求助,归并80,#2#10TLE!!!
查看原帖
萌新求助,归并80,#2#10TLE!!!
284715
遮云壑楼主2020/10/13 23:14
#include<bits/stdc++.h>
#define maxn 200010
using namespace std;

inline void read(int& x)
{
	x=0;
	int y=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')y=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	x=x*y;
}

int n,r,q;
int power[maxn];
struct node{
	int num,grade;
	bool operator <(const node & x)const
	{
		if(grade==x.grade)return num<x.num;
		else return grade>x.grade;
	}
}peo[maxn];
queue<node> q1,q2;

bool cmp(node x,node y)
{
	if(x.grade==y.grade)return x.num<y.num;
	else return x.grade>y.grade;
}

inline void merge_sort()
{
	int i=0;
	node a,b;
	a=q1.front();
	b=q2.front();
	while(!q1.empty()&&!q2.empty())
	{
		if(a<b)
		{
			peo[++i]=a;
			q1.pop();
			if(!q1.empty())a=q1.front();
		}
		else
		{
			peo[++i]=b;
			q2.pop();
			if(!q2.empty())b=q2.front();
		}
	}
	while(!q1.empty())
	{
		peo[++i]=a;
		q1.pop();
		if(!q1.empty())a=q1.front();
	}
	while(!q2.empty())
	{
		peo[++i]=b;
		q2.pop();
		if(!q2.empty())b=q2.front();
	}
}

int main(){
	read(n);read(r);read(q);
	for(int i=1;i<=n*2;i++)
	{
		read(peo[i].grade);
		peo[i].num=i;
	}
	for(int i=1;i<=n*2;i++)read(power[i]);
	sort(peo+1,peo+1+n*2,cmp);
	
	for(int i=1;i<=r;i++)
	{
		for(int j=1;j<=n*2;j+=2)
		{
			if(power[peo[j].num]>power[peo[j+1].num])
			{
				peo[j].grade+=1;
				q1.push(peo[j]);
				q2.push(peo[j+1]);
			}
			else
			{
				peo[j+1].grade+=1;
				q1.push(peo[j+1]);
				q2.push(peo[j]);
			}
		}
		merge_sort();
	}
	printf("%d\n",peo[q].num);
	return 0;
}

2020/10/13 23:14
加载中...