1 条题解

  • 0
    @ 2023-12-3 18:04:56
    #include<bits/stdc++.h>
    using namespace std;
    int a[1000005],d[1000005];
    int n,A,B,minn,maxn,have,empty,ans_have,ans_empty,flag;
    int main(){
    	ios::sync_with_stdio(false);
    	cin.tie(0),cout.tie(0);
    	cin>>n;
    	while(n--){
    		cin>>A>>B;
    		d[A]++;
    		d[B+1]--;
    		minn=min(minn,A);
    		maxn=max(maxn,B);
    	}
    	for(int i=minn;i<=maxn;i++){
    		a[i]=a[i-1]+d[i];
    		if(i>minn&&a[i]!=a[i-1])flag=1;
    		//cout<<a[i]<<" ";
    		if(a[i]){
    			have++;
    			ans_empty=max(empty,ans_empty);
    			empty=0;
    		}
    		if(!a[i]){
    			empty++;
    			ans_have=max(have,ans_have);
    			have=0;
    		}
    	}
    	if(flag==1)cout<<ans_have-1<<" "<<ans_empty+1;
    	else{
    		if(have)cout<<have<<" 0";
    		if(empty)cout<<"0 "<<empty;
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    778
    时间
    1000ms
    内存
    256MiB
    难度
    3
    标签
    递交数
    16
    已通过
    3
    上传者