传送门

贪心

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

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

用一个 $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)的更多相关文章

  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. 记录一次腾讯X5内核64位手机初始化失败

    之前一直在使用x5内核,只需要一个jar包和so文件就能让webview实现多余原生webview的水平,在32位的手机上能够正常运行,但是到了64位手机上就报如下错误: E/ERROR:: .... ...

  2. Java 面向对象(五)

    包装类 什么是包装类 在面向对象当中"一切皆对象".基本数据类型变量不是对象,比如 int a = 10; 当中就没有对象,所以就很矛盾.此时我们就可以对基本数据类型进行包装,把基 ...

  3. uefi是如何启动linux内核的?

    答:uefi启动linux内核有两条路径: 1. uefi直接进入uefi shell来启动linux内核 2. uefi直接进入uefi shell启动grub启动器,然后进入grub shell启 ...

  4. c#添加资源

    1.在项目目录下创建Resources文件夹,把需要用到的图片放到此文件夹里 2.在项目属性-资源里面添加这些图片 此时就可以在项目里看到资源文件夹及其下的图片了 3.在代码里这样使用这些图片: Im ...

  5. vue页面刷新重定向

    在App.vue中,添加如下代码: created(){ if(this.$router.path !== '/RealTimeMonitoring'){ this.$router.replace(' ...

  6. AndroidStudio制作Nine-Patch【.9】图片

    使用AndroidStudio制作Nine-Patch[.9]图片,以及为什么要制作Nine-Patch[.9]图片[以聊天气泡为例]   本文链接:https://blog.csdn.net/She ...

  7. win10安装RabbitMQ

    简单来说,两步走:先装erlang,再装rabbitmq.rabbitmq是用erlang开发的,既然erlang是一种语言,你可以把它当做Jdk来安装. 1.下载erlang安装包(官网下载地址ht ...

  8. Elasticsearch 7.x文档基本操作(CRUD)

    官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs.html 1.添加文档 1.1.指定文档ID PUT ...

  9. DELPHI中 screen.Cursor:=crhourglass; adoQuery.close; adoquery.Open; screen.Cursor:=crdefault;啥意思

    鼠标忙这段代码大概是用来演示鼠标的用法的.具体解释如下: 使鼠标指针为沙漏状.(以表示程序正忙)screen.Cursor:=crhourglass; 把(打开的)数据库关闭.adoQuery.clo ...

  10. 小程序 实现fadeIn 渐变的效果

    const winHeight = wx.getSystemInfoSync().windowHeight Page({ data: { logs: [] }, onLoad: function () ...