zoukankan      html  css  js  c++  java
  • [JZOJ 5861] 失意

    思路:
    求交集最大老套路,排序之后用堆维护即可。

    #include <bits/stdc++.h>
    using namespace std;
    const int mod = 1e9+7;
    const int maxn = 1000010;
    inline int read() {
    	int q=0,f=1;char ch = getchar();
    	while(!isdigit(ch)){
    		if(ch=='-')f=-1;ch=getchar();
    	}
    	while(isdigit(ch)){
    		q=q*10+ch-'0';ch=getchar();
    	}
    	return q*f;
    }
    struct lne {
    	int l,r,id;
    	bool operator < (lne x) const{
    		return r > x.r;
    	}
    }l[maxn];
    int ans;
    int n,m;
    priority_queue<lne> q;
    bitset<maxn>vis,p;
    int siz;
    inline bool cmp(lne a,lne b) {
    	return (a.l == b.l) ? (a.r > b.r) : (a.l < b.l);
    }
    int main () {
    	freopen("failure.in","r",stdin);
    	freopen("failure.out","w",stdout);
    	read();
    	n = read(),m = read();
    	for(int i = 1;i <= n; ++i) {
    		l[i].l = read();
    		l[i].r = read();
    		l[i].id = i;
    	}
    	sort(l + 1,l + n + 1,cmp);
    	for(int i = 1;i <= m; ++i) {
    		q.push(l[i]);
    		++siz;
    		vis[l[i].id] = 1;
    	}
    	lne top = q.top();
    	ans = max(top.r - l[m].l,0);
    	p = vis;
    	for(int i = m + 1;i <= n; ++i) {
    		q.push(l[i]);
    		++siz;
    		vis[l[i].id] = 1;
    		if(siz > m) {
    			top = q.top();
    			vis[top.id] = 0;
    			q.pop();
    			siz--;
    		}
    		if(siz == m) {
    			top = q.top();
    			int len = max(top.r - l[i].l,0);
    			if(len >= ans) {
    				ans = len;
    				p = vis;
    			}
    		}
    	}
    	printf("%d\n",ans);
    	for(int i = 1;i <= n; ++i) {
    		if(p[i]) {
    			printf("%d ",i);
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    管理ceph缓存池
    Ceph更换OSD磁盘
    crushmap磁盘智能分组
    Angular 初体验
    音视频开发-FFmpeg
    开源项目OEIP 游戏引擎与音视频多媒体(UE4/Unity3D)
    Yolov3代码分析与训练自己数据集
    整合Yolov3到UE4/Unity3D
    CUDA版Grabcut的实现
    CUDA加opencv复现导向滤波算法
  • 原文地址:https://www.cnblogs.com/akoasm/p/9618366.html
Copyright © 2011-2022 走看看