C - Covered Points Count CodeForces - 1000C (差分,离散化,统计)
C - Covered Points Count
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
30 31 33 8
Output
6 2 1
Input
31 32 45 7
Output
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.
题意:
给你n个线段
让你输出有多少个点被1~n个线段覆盖?
思路:
将线段拆成点,左端点权值为1,右端点权值为-1,离散化端点之后从左往右扫,过程中维护左端点和当前区间被多少个线段覆盖,统计答案就行了。
注意:
因为l~r线段中包括的点数是r-l+1,所以我们可以直接r++
map会根据firstkey 即ll排好序,所以可以直接for(auto : T)
细节见代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2) { ans = ans * a % MOD; } a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int *p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
ll l, r;
map<ll, ll> m;
ll ans[maxn];
int main()
{
//freopen("D:\\code\\text\\input.txt","r",stdin);
//freopen("D:\\code\\text\\output.txt","w",stdout);
gbtb;
cin >> n;
repd(i, 1, n) {
cin >> l >> r;
r++;
m[l]++;
m[r]--;
}
ll cnt = 0ll;
l = 0ll;
for (auto x : m) {
ll len = x.fi - l;
ans[cnt] += len;
l = x.fi;
cnt += x.se;
}
repd(i, 1, n) {
cout << ans[i];
if (i != n) {
cout << " ";
} else {
cout << endl;
}
}
return 0;
}
inline void getInt(int *p)
{
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
} else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}
C - Covered Points Count CodeForces - 1000C (差分,离散化,统计)的更多相关文章
- Educational Codeforces Round 46 C - Covered Points Count
C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h&g ...
- Covered Points Count(思维题)
C. Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- Covered Points Count CF1000C 思维 前缀和 贪心
Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input standa ...
- 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个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为 ...
- 【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]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...
- EDU 50 E. Covered Points 利用克莱姆法则计算线段交点
E. Covered Points 利用克莱姆法则计算线段交点.n^2枚举,最后把个数开方,从ans中减去. ans加上每个线段的定点数, 定点数用gcs(△x , △y)+1计算. #include ...
随机推荐
- python字典操作+文件操作+函数
师从百测besttest今天老牛教了些函数调用的知识,布置了个作业如下: # 1.写一个商品管理的小程序# 2.商品存在文件里面# 1.添加商品# 输入产品名称.颜色.价格# 要校验商品是否存在,价格 ...
- 【计算机】hosts设置
2015 Google hosts 持续更新[更新于:2016-02-12] 老D 9个月前 (06-23) hosts 248,284 暂无评论 12798 文章目录[ 隐藏 ] 修改hosts的 ...
- 基于vue-cli项目打包慢的定位优化过程
入职一周后,上一个前端就离职了(超级坑爹的),留下了一个比较棘手的问题,就是基于vue-cli的项目打包超级慢,我接手项目的时候,打包需要45min(上个离职者也不知道原因),经过3个月之后,随着项目 ...
- 博客C语言I作业11
一.本周教学内容&目标 第5章 函数 要求学生掌握各种类型函数的定义.调用和申明,熟悉变量的作用域.生存周期和存储类型. 二.本周作业头 这个作业属于哪个课程 c语言程序设计II 这个作业要求 ...
- Oooooooo AAAAE 【网络流最小点权覆盖】
Description “Let the bass kick!O-oooooooooo AAAAE-A-A-I-A-U- JO-oooooooooooo AAE-O-A-A-U-U-A- E-eee- ...
- Django2.2 数据库的模块model学习笔记
一.前言 为什么选用Django2.2,因为从2019年下半年起Django2.2逐渐成为长期支持版本,官网也有数据,所以当然选用维护时间长的版本 二.models的建立 Django的models也 ...
- [Comet OJ - Contest #6 D][48D 2280]另一道树题_并查集
另一道树题 题目大意: 数据范围: 题解: 这个题第一眼能发现的是,我们的答案分成两种情况. 第一种是在非根节点汇合,第二种是在根节点汇合. 尝试枚举在第几回合结束,假设在第$i$回合结束的方案数为$ ...
- 德州扑克AK打法攻略
AK是所有德扑网游中最受争议的底牌,也是一副令人又爱又恨的底牌.<德州扑克培训大师>根据国内德州扑克网游特性,为大家制作了第一套AK打法攻略,希望所有玩家从今天开始能正确认识AK,发挥AK ...
- position: sticky 防坑指南
position: sticky 防坑指南:https://www.jianshu.com/p/e217905e8b87 今天在写小程序项目的时候碰到一个需求是要把轮播图下面的标签栏滑动到顶部后固定, ...
- ARST第二周打卡
Algorithm : 做一个 leetcode 的算法题 题目:一个无序数组里有99个不重复正整数,范围从1到100,唯独缺少一个整数.如何找出这个缺失的整数? int FindOneMissNum ...