RE#10求助
查看原帖
RE#10求助
917793
BQianYi楼主2023/10/10 11:01

最后一个点RE了,请问哪里有问题(⊙_⊙)?非常感谢

#include<bits/stdc++.h>
#define MAXN 20005
using namespace std;
int a[MAXN],b[MAXN],f[2*MAXN],d[2*MAXN],n;
long long ans,c[2*MAXN];
int main()
{
	//shuru
	scanf("%d",&n);
	int top=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		d[++top]=a[i];
		d[++top]=b[i];
	}
	//chuli
	sort(d+1,d+1+top);
	int ctop=0;
	for(int i=1;i<=top;i++)
	{
		while(d[i]==d[i+1])i++;
		c[++ctop]=d[i];//erase repeated counts
	}
	for(int i=1;i<=n;i++)
	{
		int x=lower_bound(c+1,c+1+ctop,a[i])-c;//notice "=c"!
		int y=lower_bound(c+1,c+1+ctop,b[i])-c;
		for(int j=x;j<y;j++)f[j]=1;
	}
	for(int i=1;i<ctop;i++)//i<=ctop
		if(f[i])
		ans+=c[i+1]-c[i];
	//shuchu
	cout<<ans;
	return 0;
}
2023/10/10 11:01
加载中...