传送门

贪心

对于第一个不合法的位置,我们显然要通过删除几个覆盖了它的区间来使这个位置合法

显然删右端点更靠右的区间是更优的,所以就考虑优先删右端点靠右的,然后再考虑下一个不合法位置

用一个 $set$ 维护一下右端点和区间编号即可

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<vector>
  7. #include<set>
  8. using namespace std;
  9. typedef long long ll;
  10. inline int read()
  11. {
  12. int x=,f=; char ch=getchar();
  13. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  14. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  15. return x*f;
  16. }
  17. const int N=2e5+;
  18. int n,m;
  19. struct dat {
  20. int r,id;
  21. dat (int _r=,int _id=) { r=_r,id=_id; }
  22. inline bool operator < (const dat &tmp) const {
  23. return r!=tmp.r ? r<tmp.r : id<tmp.id;
  24. }
  25. };
  26. vector <dat> V[N];
  27. vector <int> mov;
  28. set <dat> S;
  29. int main()
  30. {
  31. n=read(),m=read(); int a,b,mx=;
  32. for(int i=;i<=n;i++)
  33. a=read(),b=read(),
  34. mx=max(mx,b),
  35. V[a].push_back(dat(b,i));
  36. int ans=;
  37. for(int i=;i<=mx;i++)
  38. {
  39. while(S.size()&&(*S.begin()).r<i) S.erase(S.begin());
  40. for(auto x: V[i]) S.insert(dat(x.r,x.id));
  41. while(S.size()>m)
  42. {
  43. auto p=S.rbegin();
  44. ans++,mov.push_back((*p).id);
  45. S.erase(*p);
  46. }
  47. }
  48. printf("%d\n",ans);
  49. for(auto x: mov) printf("%d ",x); puts("");
  50. return ;
  51. }

Codeforces 1249 D2. Too Many Segments (hard version)的更多相关文章

  1. codeforces 1249 D2 Too Many Segments (hard version) 贪心+树状数组

    题意 给定n个线段,线段可以相交,第\(i\)个线段覆盖的区间为\([l_i,r_i]\),问最少删除多少个线段让覆盖每个点的线段数量小于等于k. 分析 从左往右扫每个点\(x\),若覆盖点\(x\) ...

  2. Codeforces Round #535 E2-Array and Segments (Hard version)

    Codeforces Round #535 E2-Array and Segments (Hard version) 题意: 给你一个数列和一些区间,让你选择一些区间(选择的区间中的数都减一), 求最 ...

  3. 【Codeforces 1108E1】Array and Segments (Easy version)

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 枚举最大值和最小值在什么地方. 显然,只要包含最小值的区间,都让他减少. 因为就算那个区间包含最大值,也无所谓,因为不会让答案变小. 但是那些 ...

  4. codeforces 1249D1/D2 Too Many Segments (贪心)

    (点击此处查看原题) 题意说明 有n个区间,第i个区间覆盖范围[li,ri]内所有点,问删除最少哪些区间,使得所有点被区间覆盖的次数少于等于k次 解题思路 看到这个题的时候,觉得和开关(反转)问题很像 ...

  5. Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力

    Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between eas ...

  6. 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 ...

  7. Codeforces 1108E2 Array and Segments (Hard version)(差分+思维)

    题目链接:Array and Segments (Hard version) 题意:给定一个长度为n的序列,m个区间,从m个区间内选择一些区间内的数都减一,使得整个序列的最大值减最小值最大. 题解:利 ...

  8. D2. Remove the Substring (hard version)(思维 )

    D2. Remove the Substring (hard version) time limit per test 2 seconds memory limit per test 256 mega ...

  9. D2. Equalizing by Division (hard version)

    D2. Equalizing by Division (hard version) 涉及下标运算一定要注意下标是否越界!!! 思路,暴力判断以每个数字为到达态最小花费 #include<bits ...

随机推荐

  1. [Ubuntu] A start job is running for...interfaces

    CPU:RK3288 系统:Linux 移植 Ubuntu 16.04 到嵌入式平台,如果以太网有问题,在这里会耗时大约5分钟 开机后可以修改 Ubuntu 配置来缩短时间 打开下面的文件,可以看到最 ...

  2. oracle之case

    使用oracle时,不免会用到判断后转换为要展示的值,这里常用case,如下: SELECT (case ) then 'yes' ) then 'no' else 'other' end) --no ...

  3. vue设置公共常量

    Global.vue <template> </template> <script type="text/javascript"> const ...

  4. android中SpannableString之富文本显示效果

    SpannableString其实和String一样,都是一种字符串类型,SpannableString可以直接作为TextView的显示文本,不同的是SpannableString可以通过使用其方法 ...

  5. It’s worth noting值得注意的是

    It’s worth noting that in JavaScript applications the Model is often connected via Ajax to a back-en ...

  6. Flutter中的事件广播event_bus的基本使用

    官方包参考地址: https://pub.dev/packages/event_bus https://github.com/marcojakob/dart-event-bus 1.pubspec.y ...

  7. java获取两个日期之间的所有日期

    java获取两个日期之间的所有日期   解决方法: 1.核心方法 private List<String> getBetweenDates(String start, String end ...

  8. spark中的cache和persist的区别

    在使用中一直知其然不知其所以然的地使用RDD.cache(),系统的学习之后发现还有一个与cache功能类似看起来冗余的persist 点进去一探究竟之后发现cache()是persist()的特例, ...

  9. python调用shell命令

    1.subprocess介绍 官方推荐 subprocess模块,os.system(command) 这个废弃了 亲测 os.system 使用sed需要进行字符转义,非常麻烦 python3 su ...

  10. nginx+mysql双主搭建

    说明:mysql双主架构经过测试在生产环境中使用没有问题,但是还是建议使用读写分离, Mysql主主同步环境部署: centos 7.4 三台云主机:mysql1 :10.1.1.142 mysql2 ...