Too Many Segments (hard version) CodeForces - 1249D2(贪心+容器vector+set)

题目

给多组线段,而每一个点的覆盖次数不超过K,每次可去除一个线段,问最少去多少线段以及线段的位置。
The only difference between easy and hard versions is constraints.

You are given nn segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The ii-th segment is [li;ri] (li≤ri) and it covers all integer points j such that li≤j≤ri.

The integer point is called bad if it is covered by strictly more than kk segments.

Your task is to remove the minimum number of segments so that there are no bad points at all.

Input
The first line of the input contains two integers nn and kk (1≤k≤n≤2⋅10 5 ^{5} 5) — the number of segments and the maximum number of segments by which each integer point can be covered.

The next nn lines contain segments. The ii-th line contains two integers lili and riri (1≤li≤ri≤2⋅10 5 ^{5} 5) — the endpoints of the ii-th segment.

Output
In the first line print one integer mm (0≤m≤n) — the minimum number of segments you need to remove so that there are no bad points.

In the second line print mm distinct integers p1,p2,…,pm(1≤pi≤n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them.

Examples
Input
7 2
11 11
9 11
7 8
8 9
7 8
9 11
7 9
Output
3
4 6 7
Input
5 1
29 30
30 30
29 29
28 30
30 30
Output
3
1 4 5
Input
6 1
2 3
3 3
2 3
2 2
2 3
2 3
Output
4
1 3 5 6
官方题解:
In this problem, we need to implement the same greedy solution as in the easy version, but faster. Firstly, let’s calculate for each point the number of segments covering it. We can do it using standard trick with prefix sums: increase cntli, decrease cntri+1 and build prefix sums on the array cnt.

Let’s maintain the set of segments that

针对ARM Cortex-M0和Cortex-M0+微控制器的开发,Keil MDK提供了一套强的工具和优化选项,能够帮助开发者在代码小和执行效率之间取得平衡。在实际项目开发中,可以通过以下几个步骤来配置编译器以达到最优的代码优化: 参考资源链接:[ARM Cortex-M0与M0+权威指南:深入解析与实战教程](https://wenku.csdn.net/doc/646d7c5fd12cbe7ec3ea3857) 首先,打开你的Keil MDK项目,在Options for Target(项目目标选项)中进行配置。选择C/C++标签页,在Code Generation选项中,你可以调整编译器的优化级别。'Level'选项提供了多个预设值,从'None'到'Optimization Level 3'(-O3)不等。通常情况下,O2或O3级别的优化能够有效减小代码体积同时提升执行速度,但需要注意的是,某些优化可能会带来额外的执行开销,需要在特定应用场景下测试以确认效果。 其次,你还可以选择启用或禁用特定的优化选项。例如,启用'Use inline functions'(内联函数)可以减少函数调用开销,而启用'Optimize for time'(优化为时间)则可以提升执行效率。 再者,对RAM使用有特定要求的项目,可以考虑启用'Use separate I and D segments'(使用单独的I和D段)和'Optimize for space'(优化为空间),这可以帮助减少内存占用。 最后,对于项目中的特定函数,可以通过关键字`__attribute__((optimize( 参考资源链接:[ARM Cortex-M0与M0+权威指南:深入解析与实战教程](https://wenku.csdn.net/doc/646d7c5fd12cbe7ec3ea3857)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值