[JZOJ 5861] 失意
Posted akoasm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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
",ans);
for(int i = 1;i <= n; ++i) {
if(p[i]) {
printf("%d ",i);
}
}
return 0;
}
以上是关于[JZOJ 5861] 失意的主要内容,如果未能解决你的问题,请参考以下文章
2016 Multi-University Training Contest 10 [HDU 5861] Road (线段树:区间覆盖+单点最大小)