Codeforces 1249 D2. Too Many Segments (hard version)
贪心
对于第一个不合法的位置,我们显然要通过删除几个覆盖了它的区间来使这个位置合法
显然删右端点更靠右的区间是更优的,所以就考虑优先删右端点靠右的,然后再考虑下一个不合法位置
用一个 $set$ 维护一下右端点和区间编号即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=2e5+;
int n,m;
struct dat {
int r,id;
dat (int _r=,int _id=) { r=_r,id=_id; }
inline bool operator < (const dat &tmp) const {
return r!=tmp.r ? r<tmp.r : id<tmp.id;
}
};
vector <dat> V[N];
vector <int> mov;
set <dat> S;
int main()
{
n=read(),m=read(); int a,b,mx=;
for(int i=;i<=n;i++)
a=read(),b=read(),
mx=max(mx,b),
V[a].push_back(dat(b,i));
int ans=;
for(int i=;i<=mx;i++)
{
while(S.size()&&(*S.begin()).r<i) S.erase(S.begin());
for(auto x: V[i]) S.insert(dat(x.r,x.id));
while(S.size()>m)
{
auto p=S.rbegin();
ans++,mov.push_back((*p).id);
S.erase(*p);
}
}
printf("%d\n",ans);
for(auto x: mov) printf("%d ",x); puts("");
return ;
}
Codeforces 1249 D2. Too Many Segments (hard version)的更多相关文章
- codeforces 1249 D2 Too Many Segments (hard version) 贪心+树状数组
题意 给定n个线段,线段可以相交,第\(i\)个线段覆盖的区间为\([l_i,r_i]\),问最少删除多少个线段让覆盖每个点的线段数量小于等于k. 分析 从左往右扫每个点\(x\),若覆盖点\(x\) ...
- Codeforces Round #535 E2-Array and Segments (Hard version)
Codeforces Round #535 E2-Array and Segments (Hard version) 题意: 给你一个数列和一些区间,让你选择一些区间(选择的区间中的数都减一), 求最 ...
- 【Codeforces 1108E1】Array and Segments (Easy version)
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 枚举最大值和最小值在什么地方. 显然,只要包含最小值的区间,都让他减少. 因为就算那个区间包含最大值,也无所谓,因为不会让答案变小. 但是那些 ...
- codeforces 1249D1/D2 Too Many Segments (贪心)
(点击此处查看原题) 题意说明 有n个区间,第i个区间覆盖范围[li,ri]内所有点,问删除最少哪些区间,使得所有点被区间覆盖的次数少于等于k次 解题思路 看到这个题的时候,觉得和开关(反转)问题很像 ...
- Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between eas ...
- Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】
传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...
- Codeforces 1108E2 Array and Segments (Hard version)(差分+思维)
题目链接:Array and Segments (Hard version) 题意:给定一个长度为n的序列,m个区间,从m个区间内选择一些区间内的数都减一,使得整个序列的最大值减最小值最大. 题解:利 ...
- D2. Remove the Substring (hard version)(思维 )
D2. Remove the Substring (hard version) time limit per test 2 seconds memory limit per test 256 mega ...
- D2. Equalizing by Division (hard version)
D2. Equalizing by Division (hard version) 涉及下标运算一定要注意下标是否越界!!! 思路,暴力判断以每个数字为到达态最小花费 #include<bits ...
随机推荐
- html 与 xml 的区别与联系
[引言] 前一阵子刚刚学习了html(HyperText Markup Language),最近又接触了xml(Extensible Markup Language),它们之间有什么联系和区别呢?现在 ...
- Win+数字快速启动/切换指定程序
Windows键+数字,可以快速启动任务栏上的程序 按下按下Win+4桌面将切换到排序第4的程序:页也就是谷歌浏览器. 今天刚发现这个小功能. 文章来源:外星人来地球 欢迎关注,有问题一起学习欢迎 ...
- bootargs中的rootwait 与rootdelay有什么区别?
答: rootwait是无限期等待,而rootdelay可以指定等待的时间,更加灵活.
- <javaScript>通过getElementsByTagName获取标签的class值
console.log(p[1].id); console.log(p.item(1).id); console.log(p[2].getAttribute("class")); ...
- apk增加系统签名的方法
1.命令行方法给apk加系统签名在Linux环境:java -Djava.library.path=. -jar signapk.jar platform.x509.pem platform.pk8 ...
- 双缓冲技术局部更新原理之派生自SurfaceView
package com.loaderman.customviewdemo; import android.content.Context; import android.graphics.Canvas ...
- js Map对象的用法
第一篇: Map: Map是一组键值对的结构,具有极快的查找速度. 举个例子,假设要根据同学的名字查找对应的成绩,如果用Array实现,需要两个Array: var names = ['Michael ...
- ISO/IEC 9899:2011 条款6.4.5——字符串字面量
6.4.5 字符串字面量 语法 1.string-literal: encoding-prefixopt " s-char-sequenceopt " encoding- ...
- VS2015编译gdal库 debug
nmake -f makefile.vc DEBUG=1nmake /f makefile.vc installnmake /f makefile.vc devinstal E:\Visual Stu ...
- 安装配置nodejs并创建Vue项目
一.下载安装node.js 1.Node.js 官方网站下载:https://nodejs.org/en/ 2.傻瓜式安装 双加安装包,除了根据自己的需要选择安装位置外,都默认下一步. 3.验证安装 ...