求助3760贴海报
查看原帖
求助3760贴海报
826770
Xffishr楼主2023/10/9 23:58

这个代码前4个测试点没过,请问有什么问题吗谢谢

#include<bits/stdc++.h>
using namespace std;
const int Inf=9999999;
int n,m;
int a[Inf],b[Inf];
long long  d[Inf],ddd,c[Inf],ccc;
int book[Inf];
int kkk=1;
int main(){
	
	//离散化 
	cin>>n>>m;
	if(n==0||m==0)cout<<0<<endl;
	else{
			for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
		d[++ddd]=a[i];
		d[++ddd]=b[i];
	}
	//去重
	sort(d+1,d+1+ddd);
	c[++ccc]=d[1];
	for(int i=2;i<=ddd;i++){
		if(d[i-1]!=d[i])c[++ccc]=d[i];
	} 
	for(int i=1;i<=m;i++){
		int x=lower_bound(c+1,c+1+ccc,a[i])-c;
		int y=lower_bound(c+1,c+1+ccc,b[i])-c;
		for(int j=x;j<=y;j++){
			book[j]=i;
		}
	}
	sort(book+1,book+1+ccc);
	for(int i=2;i<=ccc;i++){
		if(book[i-1]!=book[i])++kkk;
	}
	cout<<kkk;
	}


	return 0;
}

2023/10/9 23:58
加载中...