传送门

贪心

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

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

用一个 $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. ML_Review_PCA(Ch4)

    Note sth about PCA(Principal Component Analysis)   ML6月20日就要考试了,准备日更博客,来记录复习一下这次ML课所学习的一些方法. 博客是在参考老 ...

  2. Vue学习手记04-跨域问题

    01-安装axios,指令(npm install --save axios)02-解决跨域问题 在config=>中创建一个新的文件proxyConfig.js module.exports ...

  3. php实现excel单元格合并,字体加粗居中等操作

    使用的是phpexcel,基本用的原生语法,所见即所得,直接复制下面代码,即可: // 引用phpexcel类 $this->load->library('PHPExcel'); // 创 ...

  4. windows2012域控

    此次主要是使用服务器搭建域控制器,我主要是用于使用office web apps 和office online server搭建在线Word预览编辑! 一.准备工作 首先准备1台比较干净的服务器,推荐 ...

  5. Windows服务器下,Tomcat制作成服务自启动,跑不起来,报内存溢出。

    测试过不行 使用服务启动后,tomcat运行时会抛出各种内存溢出错误,于是我第一时间想到的是去修改catalina.bat文件中的内存设置,但是然并卵,于是我又尝试不用服务,去使用startup.ba ...

  6. 数字图像处理--算术、几何、谐波、逆谐波均值滤波器Matlab

    本文链接:https://blog.csdn.net/Dooonald/article/details/78545461算术均值 close all clear all f=imread('D:/te ...

  7. vue - 设置全局html背景

    需求 有时候有些组件需要全局设置body背景,有些不需要在组件中设置就行了 解决思路 1. 全局设置可以是html,body,这里大家可以试一下,这两个只要其中一个设置了background,另一个的 ...

  8. IO流的标准处理代码

    FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream("aaa.t ...

  9. tensorflow cpu问题

    返回: -- ::] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 ...

  10. Access-Control-Max-Age是什么?

    Access-Control-Max-Age是什么   答: 浏览器的同源策略,就是出于安全考虑,浏览器会限制从脚本发起的跨域HTTP请求(比如异步请求GET, POST, PUT, DELETE, ...