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 ...
随机推荐
- [Ubuntu] A start job is running for...interfaces
CPU:RK3288 系统:Linux 移植 Ubuntu 16.04 到嵌入式平台,如果以太网有问题,在这里会耗时大约5分钟 开机后可以修改 Ubuntu 配置来缩短时间 打开下面的文件,可以看到最 ...
- oracle之case
使用oracle时,不免会用到判断后转换为要展示的值,这里常用case,如下: SELECT (case ) then 'yes' ) then 'no' else 'other' end) --no ...
- vue设置公共常量
Global.vue <template> </template> <script type="text/javascript"> const ...
- android中SpannableString之富文本显示效果
SpannableString其实和String一样,都是一种字符串类型,SpannableString可以直接作为TextView的显示文本,不同的是SpannableString可以通过使用其方法 ...
- It’s worth noting值得注意的是
It’s worth noting that in JavaScript applications the Model is often connected via Ajax to a back-en ...
- Flutter中的事件广播event_bus的基本使用
官方包参考地址: https://pub.dev/packages/event_bus https://github.com/marcojakob/dart-event-bus 1.pubspec.y ...
- java获取两个日期之间的所有日期
java获取两个日期之间的所有日期 解决方法: 1.核心方法 private List<String> getBetweenDates(String start, String end ...
- spark中的cache和persist的区别
在使用中一直知其然不知其所以然的地使用RDD.cache(),系统的学习之后发现还有一个与cache功能类似看起来冗余的persist 点进去一探究竟之后发现cache()是persist()的特例, ...
- python调用shell命令
1.subprocess介绍 官方推荐 subprocess模块,os.system(command) 这个废弃了 亲测 os.system 使用sed需要进行字符转义,非常麻烦 python3 su ...
- nginx+mysql双主搭建
说明:mysql双主架构经过测试在生产环境中使用没有问题,但是还是建议使用读写分离, Mysql主主同步环境部署: centos 7.4 三台云主机:mysql1 :10.1.1.142 mysql2 ...