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. 042、Java中逻辑运算之短路或运算“||”

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  2. eshop5-maven 安装

    1. Maven 安装 2.下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.0.5/binaries/ 3. 通过ta ...

  3. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-ok

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  4. linux桌面系统 镜像下载

    1.Ubuntu 官方下载地址(不推荐,网速较慢):https://www.ubuntu.com/download 阿里云:http://mirrors.aliyun.com/ubuntu-relea ...

  5. HihoCoder第七周:完全背包问题

    1043 : 完全背包 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说之前的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励的时 ...

  6. linux下nginx的安装和配置

    准备目录 [root@sqh ~]# mkdir /usr/local/nginx [root@sqh ~]# cd /usr/local/nginx 添加一些支持和依赖 1.安装gcc 安装redi ...

  7. cf 763B. Timofey and rectangles

    %%题解,脑洞好大啊. 四色定理什么鬼的..所以一定是yes. 因为矩形边长都是奇数,所以可以按左下角分类,一共4类,分别1,2,3,4就可以了. (需要4种颜色的情况大概就是4个矩形围起来一个矩形) ...

  8. swoole在线聊天学习笔记

    <?php $http=); $http->on('request',function(swoole_http_request $request,swoole_http_response ...

  9. Hibernate--起步

    1.配置对象 配置对象是你在任何 Hibernate 应用程序中创造的第一个 Hibernate 对象,并且经常只在应用程序初始化期间创造.它代表了 Hibernate 所需一个配置或属性文件.配置对 ...

  10. Java中如何序列化一个对象(转)

    转自:http://blog.csdn.net/chx10051413/article/details/40784667 http://www.cnblogs.com/baoendemao/p/380 ...