https://codeforces.com/problemset/problem/1000/C

题意:

有n个线段,覆盖[li,ri],最后依次输出覆盖层数为1~n的点的个数。

思路:

区间线段覆盖问题,第一反应树状数组、线段树,看了看数据规模,开不了这么大的空间。

只能用差分了

 代码如下:

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
#define Bug cout<<"---------------------"<<endl
const int maxn=*1e5+;
using namespace std; pair<LL,int> p[*maxn];//注意要开两倍空间
LL ans[maxn]; int main()
{
int n;
scanf("%d",&n);
int cnt = ;
for(int i = ;i < n;i++)
{
LL l,r;//注意是long long
scanf("%lld %lld",&l,&r);
p[i*] = make_pair(l,);
p[i*+] = make_pair(r+,-);
}
sort(p,p+n*);
LL now = ;//当前点的覆盖层数
for(int i = ;i < n*;i++)
{
now += p[i].second;
if(p[i].first == p[i+].first) continue;//叠加差分
ans[now] += p[i+].first - p[i].first;
}
for(int i=;i<=n;i++)
printf("%lld ",ans[i]);
return ;
}

-

CodeForces 1000C Covered Points Count(区间线段覆盖问题,差分)的更多相关文章

  1. codeforces 1000C - Covered Points Count 【差分】

    题目:戳这里 题意:给出n个线段,问被1~n个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为 ...

  2. C - Covered Points Count CodeForces - 1000C (差分,离散化,统计)

    C - Covered Points Count CodeForces - 1000C You are given nn segments on a coordinate line; each end ...

  3. Educational Codeforces Round 46 C - Covered Points Count

    C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h&g ...

  4. Covered Points Count CF1000C 思维 前缀和 贪心

     Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input standa ...

  5. Covered Points Count(思维题)

    C. Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

  6. Codeforces 1036E Covered Points (线段覆盖的整点数)【计算几何】

    <题目链接> <转载于 >>>  > 题目大意: 在二维平面上给出n条不共线的线段(线段端点是整数),问这些线段总共覆盖到了多少个整数点. 解题分析: 用GC ...

  7. Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/C 题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...

  8. Codeforces 1036E. Covered Points

    又一次写起了几何.... 特殊处理在于有可能出现多条线段交于一点的情况,每次考虑时,对每条线段与其他所有线段的交点存在一个set里,对每一个set,每次删除set.size()即可 重点在于判断两条线 ...

  9. 【CF1000C】Covered Points Count(离散化+差分)

    点此看题面 大致题意: 给出\(n\)条线段,分别求有多少点被覆盖\(1\)次.\(2\)次...\(n\)次. 正常的算法 好吧,这道题目确实有个很简单的贪心做法(只可惜我做的时候没有想到,结果想了 ...

随机推荐

  1. 06.Delphi接口的不对等的多重继承

    uSayHello代码如下 unit uSayHello; interface uses SysUtils, Windows, Messages, Classes, Graphics, Control ...

  2. 树莓派 Raspberry 软件源更改 看门狗启用

    看门狗无法在pi1上执行,似乎后更高级的pi上面才可用 1.替换脚本 下面脚本请直接复制到终端执行!! 适用于raspbian-stretch(基于Debian9) sudo -s echo -e & ...

  3. 如何修改 Vmware vRealize Operations Manager Appliance root密码

    开机后,按上下键,选择 中间那一项,在底部增加:init=/bin/bash 进入单用户模式后,输入命令:# passwd root                      #修改root密码,要输 ...

  4. arduino 通过串口接收string,int类型数据

    串口接收string类型数据源码如下 String comdata = ""; void setup() {     Serial.begin(9600); }   void lo ...

  5. JAVA - 创建SpringBoot项目

    JAVA - 创建SpringBoot项目 Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配 ...

  6. redis十-对快照模式分析

    复制自:http://www.cnblogs.com/huangxincheng/p/5010795.html 一:快照模式 或许在用Redis之初的时候,就听说过redis有两种持久化模式,第一种是 ...

  7. C# Stream篇(二) -- TextReader 和StreamReader

    TextReader 和StreamReader 目录: 为什么要介绍 TextReader? TextReader的常用属性和方法 TextReader 示例 从StreamReader想到多态 简 ...

  8. springboot - 映射 HTTP Response Status Codes 到自定义 JSP Error 页面

    1.总览 2.代码 1).pom.xml <dependencies> <dependency> <groupId>org.springframework.boot ...

  9. POJ 1068:Parencodings

    Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22849   Accepted: 13394 De ...

  10. vnpy交易学习接口(2)

    #来源于github下载vnpy版本  20180413 11.多投资标的情况下,该如何修改? 10.stop和limit报单有什么区别呢? 在交易时用得最多的是二类定单,第一类是市价单(Market ...