Covered Points Count CF1000C 思维 前缀和 贪心
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.
给你n条线段的开始点和结束点,问被1-n条线段覆盖的点的个数
记录每个点的位置,以及他是开始点还是结束点,放在一个数组里。然后按从小到大排序,用一个cnt记录下现在覆盖了几条线段,接着直接遍历,加上每段点数,遇到开始点cnt+1,遇到结束点cnt-1
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 5e5 + ;
const int mod = 1e9 + ;
typedef long long ll;
struct node {
ll first, second;
};
node a[maxn];
ll ans[maxn];
bool cmp( node p, node q ) {
return p.first < q.first;
}
int main() {
ll n;
while( cin >> n ) {
memset( ans, , sizeof(ans) );
for( ll i = ; i <= n; i ++ ) {
ll l, r;
cin >> l >> r;
a[i*-].first = l, a[i*].first = r+;
a[i*-].second = , a[i*].second = -;
}
ll cnt = ;
sort( a + , a + *n + , cmp );
for( ll i = ; i <= *n; i ++ ) {
ans[cnt] += a[i].first - a[i-].first;
cnt += a[i].second;
}
for( ll i = ; i <= n; i ++ ) {
if( i != n ) {
cout << ans[i] << " ";
} else {
cout << ans[i] << endl;
}
}
}
return ;
}
Covered Points Count CF1000C 思维 前缀和 贪心的更多相关文章
- Covered Points Count(思维题)
C. Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- 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\)次. 正常的算法 好吧,这道题目确实有个很简单的贪心做法(只可惜我做的时候没有想到,结果想了 ...
- 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的点的个数. 思路: 区间线段覆盖 ...
- codeforces 1000C - Covered Points Count 【差分】
题目:戳这里 题意:给出n个线段,问被1~n个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为 ...
- EDU 50 E. Covered Points 利用克莱姆法则计算线段交点
E. Covered Points 利用克莱姆法则计算线段交点.n^2枚举,最后把个数开方,从ans中减去. ans加上每个线段的定点数, 定点数用gcs(△x , △y)+1计算. #include ...
随机推荐
- 荔枝FM前端面试题
最近接到了荔枝FM的面试通知,遗憾的是没有拿到offer,但是这次面试呢,还是收获很大的,下面就来给大家说说我遇到的面试题 一面 一面是直接发了一套面试题到邮箱,开启了防作弊的,限时20分钟做完,下面 ...
- JSON合并,并按时间排序
mergeJson: function (json1, json2) { var json = Object.assign([], json1, json2); return json.sort(fu ...
- Docker系列之烹饪披萨(二)
前言 上一篇我们讲解了虚拟机和容器的区别,本节我们来讲讲Docker中关于Dockerfile.镜像.容器等基本概念.Docker是一个在容器内开发.部署.运行应用程序的平台,Docker本质上是容器 ...
- Python学习系列(三)Python 入门语法规则1
一.注释 ''' 多行注释 ''' #单行注释 ''' #example1.1 测试程序 时间:4/17/2017 i1=input("请输入用户名:") i2=input ...
- Go和Python学习计划
计划虽然不一定能实现,但还是要有的,万一实现了呢. 一.学习Go 1.先看尚雪谷https://www.bilibili.com/video/av48141461/?p=12的go语言全套,把基础的过 ...
- 洛谷 P5367 【模板】康托展开(数论,树状数组)
题目链接 https://www.luogu.org/problem/P5367 什么是康托展开 百度百科上是这样说的: “康托展开是一个全排列到一个自然数的双射,常用于构建哈希表时的空间压缩. ...
- h5微信分享
h5分享的步骤(前端需要完成的部分) 1.绑定域名 登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”. 2.引入Js文件 在需要调用JS接口的页面引入如下JS文件,(支持ht ...
- netty源码解解析(4.0)-17 ChannelHandler: IdleStateHandler实现
io.netty.handler.timeout.IdleStateHandler功能是监测Channel上read, write或者这两者的空闲状态.当Channel超过了指定的空闲时间时,这个Ha ...
- 对平底锅和垃圾的O奖论文的整理和学习[1](2018-02-08发布于知乎)
今天和杉杉同志在Pacific Coffee坐了0.4天,目前两人都处于放空状态. 这种天气有暖气真的太棒了. 我今天看的论文是这两篇: MCM2013B题O奖论文MCM2016B题O奖论文 先说第一 ...
- OCP培训 Oracle 12c/18c/19c OCP认证实战培训【送OCP优惠名额】
一.OCP培训 Oracle 12c/18c/19c OCP认证全套实战培训[送OCP优惠名额],本课程内容 课程目标: 为满足想参加Oracle OCP考证的学员,风哥设计的一套比较全面OCP实战培 ...