Covered Points Count(思维题)
3 seconds
256 megabytes
standard input
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.
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.
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.
3
0 3
1 3
3 8
6 2 1
3
1 3
2 4
5 7
5 2 0
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(思维题)的更多相关文章
- Covered Points Count CF1000C 思维 前缀和 贪心
Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input standa ...
- Educational Codeforces Round 46 C - Covered Points Count
C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h&g ...
- C - Covered Points Count CodeForces - 1000C (差分,离散化,统计)
C - Covered Points Count CodeForces - 1000C You are given nn segments on a coordinate line; each end ...
- 【CF1000C】Covered Points Count(离散化+差分)
点此看题面 大致题意: 给出\(n\)条线段,分别求有多少点被覆盖\(1\)次.\(2\)次...\(n\)次. 正常的算法 好吧,这道题目确实有个很简单的贪心做法(只可惜我做的时候没有想到,结果想了 ...
- codeforces 1000C - Covered Points Count 【差分】
题目:戳这里 题意:给出n个线段,问被1~n个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为 ...
- cf1000C Covered Points Count (差分+map)
考虑如果数字范围没有这么大的话,直接做一个差分数组就可以了 但现在变大了 所以要用一个map来维护 #include<bits/stdc++.h> #define pa pair<i ...
- Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count
Bryce1010模板 http://codeforces.com/problemset/problem/1000/C 题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...
- CodeForces 1000C Covered Points Count(区间线段覆盖问题,差分)
https://codeforces.com/problemset/problem/1000/C 题意: 有n个线段,覆盖[li,ri],最后依次输出覆盖层数为1~n的点的个数. 思路: 区间线段覆盖 ...
- 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 ...
随机推荐
- 通过SVI实现VLAN间通信
两个不同网段的计算机与三层交换机直连,通过SVI实现VLAN间通信vlan 1 //几个不同网段就创建几个VLANvlan 2 int f0/1 //划分VLANswitchport mode acc ...
- Kubernetes-Envoy(一种全新的Ingress实现方式)
Ingress 在讲Envoy之前,先介绍一下Kubernetes中Service的表现形式为IP:Port,及工作在Ingress:TCP/IP层.而对于基于HTTP的服务来说,不同的URL地址经常 ...
- HBase配置和使用
参考官方文档 整体实现框架 图1 以下几个为组成部件 21892 HMaster 22028 HRegionServer 21553 QuorumPeerMain 2366 NameNode 2539 ...
- jenkins 构建部署时tomcat7 内存溢出解决方案
在使用jenkins构建部署时一直出现tomcat7内存溢出 WARNING: Unexpected node monitoring termination: Clock Difference jav ...
- Linux安装mysql以及安装时踩下的坑
安装: 检测是否已经安装了mysql rpm -qa | grep mysql 如果已经安装了,将其卸载,如: rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86 ...
- Cyclone IV器件的逻辑单元和逻辑阵列快
1. 逻辑单元 (LE) 在 Cyclone IV 器件结构中是最小的逻辑单位.LE 紧密且有效的提供了高级功能的逻辑使用.每个 LE 有以下特性:一个四口输入的查找表 (LUT),以实现四种变量的任 ...
- Android Studio引入AAR文件
一.编译生成AAR文件 二.把AAR文件复制到项目的libs目录下 三.在项目的配置文件中加入如下代码: android { //other code repositories{ flatDir{ d ...
- kafka常用命令笔记
0.查看有哪些主题: ./kafka-topics.sh --list --zookeeper 192.168.0.201:12181 1.查看topic的详细信息 ./kafka-topics.sh ...
- 九度OJ--Q1166
import java.text.DecimalFormat;import java.util.Scanner; /* * 题目描述: * 立方根的逼近迭代方程是 y(n+1) = y(n)*2/3 ...
- 九度OJ--Q1164
import java.util.Scanner; /* * 题目描述: * 任意输入两个9阶以下矩阵,要求判断第二个是否是第一个的旋转矩阵,如果是,输出旋转角度(0.90.180.270),如果不是 ...