1 条题解

  • -3
    @ 2026-9-16 11:30:32

    赛时差分打炸了。

    我们可以先合并所有的槽是剩下的槽互不重叠,然后对于每一个牛,他的贡献最多为 11,使用差分即可。

    #include<bits/stdc++.h>
    #define int long long
    #define I_love_ch ios::sync_with_stdio(0)
    #define China cin.tie(0)
    #define France cout.tie(0)
    #define ch_France return 0
    using namespace std;
    struct node{
    	int l,r;
    }b[1000010];
    bool cmp(node x,node y){
    	return x.l<y.l;
    }
    int n,m,a[1000010],ans[2000010];
    signed main(){
    	I_love_ch;
    	China;
    	France;
    	cin>>n>>m;
    	for(int i=1;i<=n;i++){
    		cin>>a[i];
    	}
    	for(int i=1;i<=m;i++){
    		cin>>b[i].l>>b[i].r;
    	}
    	sort(b+1,b+m+1,cmp);
    	int mm=m;
    	for(int i=2;i<=m;i++){
    		if(b[i].l<=b[i-1].r){
    			mm--;
    			b[i].r=max(b[i-1].r,b[i].r);
    			b[i].l=b[i-1].l;
    			b[i-1].l=1e9;
    		}
    	}
    	sort(b+1,b+m+1,cmp);
    	m=mm;
    	for(int i=1;i<=n;i++){
    		for(int j=1;j<=m;j++){
    			ans[b[j].l-a[i]+1000000]++;
    			ans[b[j].r-a[i]+1+1000000]--;
    		}
    	}
    	int maxx=0,res=0;
    	for(int i=1;i<=2e6;i++){
    		ans[i]+=ans[i-1];
    		if(ans[i]>maxx){
    			maxx=ans[i];
    			res=abs(i-1e6);
    		}
    		else if(ans[i]==maxx&&res>abs(i-1e6)) res=abs(i-1e6);
    	}
    	cout<<res<<" "<<maxx<<"\n";
    	ch_France;
    }
    
    • 1

    信息

    ID
    863
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    45
    已通过
    7
    上传者