CodeForces 1000C Covered Points Count(区间线段覆盖问题,差分)
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(区间线段覆盖问题,差分)的更多相关文章
- codeforces 1000C - Covered Points Count 【差分】
题目:戳这里 题意:给出n个线段,问被1~n个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为 ...
- C - Covered Points Count CodeForces - 1000C (差分,离散化,统计)
C - Covered Points Count CodeForces - 1000C You are given nn segments on a coordinate line; each end ...
- Educational Codeforces Round 46 C - Covered Points Count
C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h&g ...
- Covered Points Count CF1000C 思维 前缀和 贪心
Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input standa ...
- Covered Points Count(思维题)
C. Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 1036E Covered Points (线段覆盖的整点数)【计算几何】
<题目链接> <转载于 >>> > 题目大意: 在二维平面上给出n条不共线的线段(线段端点是整数),问这些线段总共覆盖到了多少个整数点. 解题分析: 用GC ...
- Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count
Bryce1010模板 http://codeforces.com/problemset/problem/1000/C 题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...
- Codeforces 1036E. Covered Points
又一次写起了几何.... 特殊处理在于有可能出现多条线段交于一点的情况,每次考虑时,对每条线段与其他所有线段的交点存在一个set里,对每一个set,每次删除set.size()即可 重点在于判断两条线 ...
- 【CF1000C】Covered Points Count(离散化+差分)
点此看题面 大致题意: 给出\(n\)条线段,分别求有多少点被覆盖\(1\)次.\(2\)次...\(n\)次. 正常的算法 好吧,这道题目确实有个很简单的贪心做法(只可惜我做的时候没有想到,结果想了 ...
随机推荐
- Java连载67-深入一维数组、main方法中的args参数详解
一.复习了一维数组,还复习了强制类型转换的注意点. package com.bjpowernode.java_learning; public class D67_1_GoDeepIntoArrays ...
- System.Data.SqlClient.SqlException: 'Incorrect syntax near 'OFFSET'.
https://www.nopcommerce.com/boards/t/54586/410-not-running-on-local-system.aspx#209684 Hello, I was ...
- ubuntu18.04下安装oh-my-zsh
安装 sudo apt-get install zsh wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/ra ...
- windows搭建安装react-native环境
在win10环境下,利用Genymotion模拟器,配置react-native的环境. 一.安装JDK 在网上下载jdk,版本最好是1.8以上.安装后要对环境变量进行配置. 同时在 Path 中配置 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-cloud
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- NO14 快照-克隆-必须掌握的Linux目录结构
壹 VMware克隆,快照讲解及相应问题讲解: ·快照:比喻:假设把人生作一个快照.1岁10岁20岁6无限还原到前一个设置的节点. ·克隆学习一般用链接克隆,不另外占用磁盘,但是依赖本体虚拟机.完整 ...
- L2d插件
<script src="https://blog-static.cnblogs.com/files/yyhh/L2Dwidget.min.js"></scrip ...
- CAN分帧接收实现
该版本程序实现了上电后先发送MACID检测功能,如果网络上有应答.则一直进行死循环,直到用户更改了本机的ID地址 才可以跳出循环体. 本单片机设置为双滤波 ,使目标地址为0X1F 实现了建立连接命令 ...
- P1057 数零壹
P1057 数零壹 转跳点:
- checkbox checked属性值
记住我1<input type='checkbox' /> 记住我2<input type='checkbox' /> <button onclick='hehe();' ...