The Union of k-Segments CodeForces - 612D (思维)

You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others.

Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 106) — the number of segments and the value of k.

The next n lines contain two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109) each — the endpoints of the i-th segment. The segments can degenerate and intersect each other. The segments are given in arbitrary order.

Output
First line contains integer m — the smallest number of segments.

Next m lines contain two integers aj, bj (aj ≤ bj) — the ends of j-th segment in the answer. The segments should be listed in the order from left to right.

Example
Input
3 2
0 5
-3 2
3 8
Output
2
0 2
3 5
Input
3 2
0 5
-3 3
3 8
Output
1
0 5

一开始思路就错了,先用了离散化,然后再前缀和计算覆盖数,但是这种写法,没有办法记录到点,只能记录线段。第17个case就错了。
这题我觉得算是区间版的离散和,动态维护覆盖数。本质是一样的。

#include<iostream>
#include<cstdio>
#include<stack>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cmath>
#define maxx 10050
#define mod 9901
using namespace std;
struct node
{
    int val;
    int o;
}p[2000005];
bool cmp(node x1, node x2)
{
    if(x1.val!=x2.val)
        return x1.val<x2.val;
    return x1.o>x2.o;
}
int l[1000005];
int r[1000005];
int cnt=0;
int main()
{
    int n,k;
    cin>>n>>k;
    int x,y;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&x,&y);
        p[cnt].val=x;
        p[cnt++].o=1;
        p[cnt].val=y;
        p[cnt++].o=0;
    }
    sort(p,p+cnt,cmp);
    int countt=0;
    int t=0;
    int i=0;
    bool sign=false;
    while(i<cnt)
    {
        if(p[i].o)
        {
            countt++;
            if(!sign)
                if(countt>=k)
                    l[t]=p[i].val,sign=true;

        }
        else
        {
            countt--;
            if(sign)
                if(countt<k)
                    r[t++]=p[i].val,sign=false;
        }
        i++;
    }
    cout<<t<<endl;
    for(int i=0;i<t;i++)
        cout<<l[i]<<" "<<r[i]<<endl;
    return 0;
}
### AD24 中 Micro-Segments 的定义、功能与概念 在网络架构设计领域,特别是针对高级分布式系统 (Advanced Distributed System, ADS),微分段(Micro-Segments)是一种用于增强网络安全性和优化资源分配的技术。以下是关于 AD24 微分段的具体描述: #### 1. **Micro-Segments 的定义** Micro-Segments 是一种逻辑上的隔离单元,在 AD24 系统中被用来划分不同的流量路径或数据处理区域。通过这种方式,可以实现更细粒度的安全策略实施以及性能调优[^1]。 #### 2. **Micro-Segments 的功能** - **安全性提升**: Micro-Segments 可以限制特定应用之间的通信范围,从而减少潜在攻击面。即使某一区域内发生安全事件,其影响也能被有效遏制。 - **资源管理**: 不同的 Micro-Segments 能够配置专属带宽限额或其他 QoS 参数,确保关键业务获得优先级服务。 - **灵活性支持**: 对于动态变化的工作负载环境来说,利用 Micro-Segmentation 技术可以根据实时需求调整边界条件而不必重新规划整个基础架构[^2]. #### 3. **Micro-Segments 的概念** 从技术角度来看,Micro-Segments 并不是物理设备或者硬件组件而是基于软件定义的方式创建出来的虚拟分区。它依赖于底层协议栈所提供的地址解析机制完成跨域访问请求定位过程[^3]。例如当涉及到多个相互协作但又各自独立运行的应用程序实例时,则可通过预先设定好的映射表快速确定目标位置并建立连接通道。 ```python def create_micro_segment(segment_id, resource_limits): """ 创建一个新的 micro-segment 实例 Args: segment_id (str): 新建segment唯一标识符 resource_limits (dict): 设置该segment内的资源配置参数 Returns: dict: 返回新创建micro-segment的信息结构体 """ new_segment = { 'id': segment_id, 'resources': resource_limits, 'status': 'active' } return new_segment ``` 上述代码片段展示了如何在一个抽象层面上初始化一个具有指定ID和资源约束的新micro-segment对象。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值