求数据加强
查看原帖
求数据加强
59361
找不到该用户楼主2021/10/26 19:39

有没有人能卡掉nnn\sqrt{n}的算法

#include <bits/stdc++.h>
using namespace std;
struct stc
{
	int a,b,c;
}a[100010],b[100010];
int n,tem1,tem2,l,s,t,t1=0,t2=0,tmax=0;
int c[100010],d[100010];
bool cmp(stc a,stc b) {return a.a<b.a;}
int worka(int t)
{
	a[t].c=0;
	int l=t+1,r=tem1,mid,ans=tem1+1;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (a[mid].a>a[t].b)
		{
			r=mid-1;
			ans=mid;
		} else l=mid+1;
	}
	while (a[ans].c==0&&ans<=tem1) ans++;
	if (ans>tem1) return 1;
	return worka(ans)+1;
}
int workb(int t)
{
	b[t].c=0;
	int l=t+1,r=tem2,mid,ans=tem2+1;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (b[mid].a>b[t].b)
		{
			r=mid-1;
			ans=mid;
		} else l=mid+1;
	}
	while (b[ans].c==0&&ans<=tem2) ans++;
	if (ans>tem2) return 1;
	return workb(ans)+1;
}
int main()
{
	scanf("%d%d%d",&n,&tem1,&tem2);
	for (int i=1;i<=tem1;i++)
	{
		scanf("%d%d",&a[i].a,&a[i].b);
		a[i].c=1;
	}
	sort(a+1,a+1+tem1,cmp);
	for (int i=1;i<=tem2;i++)
	{
		scanf("%d%d",&b[i].a,&b[i].b);
		b[i].c=1;
	}
	sort(b+1,b+1+tem2,cmp);
	c[0]=0;d[0]=0;
	l=1;s=0;
	while (l<=tem1&&t1<n)
	{
		if (a[l].c) c[++t1]=worka(l);
		l++;s=s+c[t1];
		if (s>316)
		{
			t=0;
			for (int i=1;i<=tem1;i++) if (a[i].c) a[++t]=a[i];
			tem1=t;
			l=1;s=0;
		}
	}
	l=1;s=0;
	while (l<=tem2&&t2<n)
	{
		if (b[l].c) d[++t2]=workb(l);
		l++;s=s+d[t2];
		if (s>316)
		{
			t=0;
			for (int i=1;i<=tem2;i++) if (b[i].c) b[++t]=b[i];
			tem2=t;
			l=1;s=0;
		}
	}
	for (int i=t1+1;i<=n;i++) c[i]=0;
	for (int i=t2+1;i<=n;i++) d[i]=0;
	for (int i=1;i<=n;i++) c[i]=c[i]+c[i-1];
	for (int i=1;i<=n;i++) d[i]=d[i]+d[i-1];
	for (int i=0;i<=n;i++) tmax=max(tmax,c[i]+d[n-i]);
	printf("%d\n",tmax);
	return 0;
}
2021/10/26 19:39
加载中...