C. Covered Points Count
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given nn segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.

Your task is the following: for every k∈[1..n]k∈[1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals kk. A segment with endpoints lili and riri covers point xx if and only if li≤x≤rili≤x≤ri.

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of segments.

The next nn lines contain segments. The ii-th line contains a pair of integers li,rili,ri (0≤li≤ri≤10180≤li≤ri≤1018) — the endpoints of the ii-th segment.

Output

Print nn space separated integers cnt1,cnt2,…,cntncnt1,cnt2,…,cntn, where cnticnti is equal to the number of points such that the number of segments that cover these points equals to ii.

Examples
input

Copy
3
0 3
1 3
3 8
output

Copy
6 2 1 
input

Copy
3
1 3
2 4
5 7
output

Copy
5 2 0 
Note

The picture describing the first example:

Points with coordinates [0,4,5,6,7,8][0,4,5,6,7,8] are covered by one segment, points [1,2][1,2] are covered by two segments and point [3][3] is covered by three segments.

The picture describing the second example:

Points [1,4,5,6,7][1,4,5,6,7] are covered by one segment, points [2,3][2,3] are covered by two segments and there are no points covered by three segments.

这题坑点比较多,没有开LLwa一发 ,数组开小了又wa一发 难受

细节方面很多都没有注意到

 

 这题是纯思维题 把每一个区间分为两个点一个左端点一个右端点

进行排序一下,就出来了

从左往右扫一遍经历一次左端点就加一,经历一次又端点就减一

这个规律看图一下就出来了

 #include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + ;
typedef long long LL;
struct node {
LL x, y;
node (LL x, LL y) : x(x), y(y) {}
node () {}
} qu[maxn];
int cmp(node a, node b) {
if (a.x == b.x) return a.y > b.y;
return a.x < b.x;
}
LL ans[maxn];
int main() {
LL n,k=,a,b;
scanf("%lld", &n);
for (int i = ; i < n ; i++) {
scanf("%lld%lld",&a,&b);
qu[k++] = node(a, );
qu[k++] = node(b + , -);
}
sort(qu, qu + k, cmp);
LL temp = ;
for(int i = ; i < k- ; i++ ) {
temp += qu[i].y;
if (qu[i].x != qu[i + ].x) ans[temp]+= qu[i + ].x - qu[i].x;
}
for (int i = ; i <=n ; i++)
printf("%lld ", ans[i]);
printf("\n");
return ;
}

Covered Points Count(思维题)的更多相关文章

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

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

  2. Educational Codeforces Round 46 C - Covered Points Count

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

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

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

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

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

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

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

  6. cf1000C Covered Points Count (差分+map)

    考虑如果数字范围没有这么大的话,直接做一个差分数组就可以了 但现在变大了 所以要用一个map来维护 #include<bits/stdc++.h> #define pa pair<i ...

  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 1000C Covered Points Count(区间线段覆盖问题,差分)

    https://codeforces.com/problemset/problem/1000/C 题意: 有n个线段,覆盖[li,ri],最后依次输出覆盖层数为1~n的点的个数. 思路: 区间线段覆盖 ...

  9. UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)

    UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...

随机推荐

  1. [转载]三小时学会Kubernetes:容器编排详细指南

    原翻译by梁晓勇 原英文:Learn Kubernetes in Under 3 Hours: A Detailed Guide to Orchestrating Containers 我很奇怪,为什 ...

  2. 大数据de 2文章

    点击可免费试用网易有数 文章来源:网易有数的搭积木原则阐述 ,经作者文雯授权发布 wo ceceshi 相关文章:[推荐] SpringBoot入门(五)--自定义配置

  3. android中接入twitter进行第三方登录

    在应用中接入Twitter进行第三方登录时,开发人员遇到了一点问题,主要是概念有点混乱,这里把经验记录一下,帮助遇到同样问题的朋友. 一.注册应用并配置登录权限 这一步比较简单,就不多说了,直接去官网 ...

  4. list 集合addAll 和 add 方法小坑

    1.问题 我们经常会遍历 list集合,在遍历的过程中,如果在遍历的过程中添加了 add()  或者 addAll() 方法修改了遍历的list列表,那么会报错. 代码演示: List<Inte ...

  5. JMeter接口响应数据出现乱码的三种解决方法

    第一种方法: Content encoding设置为utf-8,若仍为乱码,请用方法2 图1 第二种方法: 修改bin文件夹下的jmeter.properties文件 搜索ISO,把“#sampler ...

  6. Java中的while(true)

    while(true)是一个无限循环 在内部用break或return退出循环,否则一直循环

  7. adb usage

    使用安卓调试及自动化,不可避免的要使用adb,说明看起来很麻烦,进行简单记录,以便时候不时之需. usb连接手机调试就很简单了.首先,在手机端开启usb调试,即点击安卓版本项7次,就可以显示开发者菜单 ...

  8. ardupilot_gazebo仿真(四)

    ardupilot_gazebo仿真(四) 标签(空格分隔): 未分类 Multi-MAV simulation 参考官网给出的multi-vehicle-simulation的方法 在每次打开sim ...

  9. 目标检测之Faster-RCNN的pytorch代码详解(模型训练篇)

    本文所用代码gayhub的地址:https://github.com/chenyuntc/simple-faster-rcnn-pytorch  (非本人所写,博文只是解释代码) 好长时间没有发博客了 ...

  10. tomcat中配置JNDI方法

    1.项目中spring的数据源配置: <bean id="dataSource" class="org.springframework.jndi.JndiObjec ...