[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;
}
[JZOJ 5861] 失意的更多相关文章
- hdu 5861 Road 两棵线段树
传送门:hdu 5861 Road 题意: 水平线上n个村子间有 n-1 条路. 每条路开放一天的价格为 Wi 有 m 天的操作,每天需要用到村子 Ai~Bi 间的道路 每条路只能开放或关闭一次. ( ...
- HDU 5861 Road (线段树)
Road 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Description There are n villages alo ...
- (jzoj snow的追寻)线段树维护树的直径
jzoj snow的追寻 DFS序上搞 合并暴力和,记录最长链和当前最远点,距离跑LCA # include <stdio.h> # include <stdlib.h> # ...
- [jzoj]3506.【NOIP2013模拟11.4A组】善良的精灵(fairy)(深度优先生成树)
Link https://jzoj.net/senior/#main/show/3506 Description 从前有一个善良的精灵. 一天,一个年轻人B找到她并请他预言他的未来.这个精灵透过他的水 ...
- [jzoj]3468.【NOIP2013模拟联考7】OSU!(osu)
Link https://jzoj.net/senior/#main/show/3468 Description osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: ...
- [jzoj]5478.【NOIP2017提高组正式赛】列队
Link https://jzoj.net/senior/#main/show/5478 Description Sylvia 是一个热爱学习的女孩子. 前段时间,Sylvia 参加了学校 ...
- [jzoj]1115.【HNOI2008】GT考试
Link https://jzoj.net/senior/#main/show/1115 Description 申准备报名参加GT考试,准考证号为n位数X1X2X3...Xn-1Xn(0<=X ...
- [jzoj]2538.【NOIP2009TG】Hankson 的趣味题
Link https://jzoj.net/senior/#main/show/2538 Description Hanks 博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫H ...
- [jzoj]4216.【NOIP2015模拟9.12】平方和
Link https://jzoj.net/senior/#main/show/4216 Description 给出一个N个整数构成的序列,有M次操作,每次操作有一下三种: ①Insert Y X, ...
随机推荐
- Python内部变量与外部变量
def outer(): x = 'outer x' def inner(): x = 'inner x' print(x) inner() print(x) # 这里的`x`与`x = 'outer ...
- bzoj1047题解
[解题思路] (p.s.:刚看的时候一脸懵逼..没看见N已经给定了,还以为要用某些高明的方法..果然还是太naive了..) 两遍预处理,第一遍处理出f[i][j][0/1]表示第i行从j-n+1~j ...
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i
参考资料: http://blog.csdn.net/competerh_programing/article/details/7377950 在创建Dialog的时候,出现: The method ...
- (15)centos7 系统服务
centos7 服务启动脚本在 /usr/lib/systemd目录下 1.服务基本操作指令 systemclt [command] [unit] #其中command包括: #start 立即启动 ...
- Editor REST Client
Editor REST Client 制作一个http请求 请求行 GET https://example.com/comments/1 HTTP/1.1 POST https://example.c ...
- java 8 bug
jpa保存实体的时候,不能用{{}}初始化对象,否则会报异常 org.springframework.dao.InvalidDataAccessApiUsageException: Unknown e ...
- CM 安装CDH 错误: 安装失败。 无法接收 Agent 发出的检测信号。
在安装CDH的时候出现错误提示: 安装失败. 无法接收 Agent 发出的检测信号. 日志提示错误: start >> raise socket.error(msg) >>er ...
- Python移动自动化测试面试✍✍✍
Python移动自动化测试面试 整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程本身没问题,大家看的时候可以 ...
- D3.js(v3)+react 制作 一个带坐标与比例尺的散点图 (V3版本)
上一章做了柱形图,https://www.cnblogs.com/littleSpill/p/10835041.html 这一章做散点图. 散点图(Scatter Chart),通常是一横一竖 ...
- 开启SSH 使用SSH登录工具连接虚拟机
修改sshd_config文件,命令为:vi /etc/ssh/sshd_config将#PermitRootLogin without-password注释去掉修改为PermitRootLogin ...