cf1000C Covered Points Count (差分+map)
考虑如果数字范围没有这么大的话,直接做一个差分数组就可以了
但现在变大了 所以要用一个map来维护
#include<bits/stdc++.h>
#define pa pair<int,int>
#define CLR(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=2e5+; inline ll rd(){
ll x=;char c=getchar();int neg=;
while(c<''||c>''){if(c=='-') neg=-;c=getchar();}
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return x*neg;
} map<ll,int> cnt;
ll ans[maxn]; int main(){
int i;
int N=rd();
for(i=;i<=N;i++){
ll l=rd(),r=rd();
cnt[l]++,cnt[r+]--;
}
ll j=,k=;
for(map<ll,int>::iterator it=cnt.begin();it!=cnt.end();it++){
ans[k]+=(it->first-j);
k+=it->second;j=it->first;
}
for(i=;i<=N;i++){
printf("%I64d ",ans[i]);
}
return ;
}
cf1000C Covered Points Count (差分+map)的更多相关文章
- Covered Points Count CF1000C 思维 前缀和 贪心
Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input standa ...
- 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(思维题)
C. Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- 【CF1000C】Covered Points Count(离散化+差分)
点此看题面 大致题意: 给出\(n\)条线段,分别求有多少点被覆盖\(1\)次.\(2\)次...\(n\)次. 正常的算法 好吧,这道题目确实有个很简单的贪心做法(只可惜我做的时候没有想到,结果想了 ...
- 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个线段覆盖的点分别有多少. 解题思路: 这题很容易想到排序后维护每个端点被覆盖的线段数,关键是端点值不好处理.比较好的做法是用差分的思想,把闭区间的线段改为 ...
- 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 ...
随机推荐
- Oracle 社区动态、中文讲座,最佳实践
https://community.oracle.com/thread/3789691https://community.oracle.com/community/support/%E4%B8%AD% ...
- [Python]Python Class 中的 函数定义中的 self
In [80]: class MyClass001: ....: def selfDemo(self): ....: print 'My Demo' ....: In [81]: p = MyClas ...
- springboot 发送邮件+模板+附件
package com.example.demo; import org.junit.Test;import org.junit.runner.RunWith;import org.springfra ...
- REST-framework快速构建API--分页
分页简介 当数据量特别大的时候,我们通过API获取数据会非常慢,所以此时我们需要将数据"分批次"取出来,这里的"分批次"就是,分页! REST框架支持自定义分页 ...
- Quartz.Net分布式任务管理平台(续)
感谢@Taking园友得建议,我这边确实多做了一步上传,导致后面还需处理同步上传到其他服务器来支持分布式得操作.所有才有了上篇文章得完善. 首先看一下新的项目结构图: 这个图和上篇文章中 ...
- linux-文件数据操作awk命令
最后一列是:交互外壳 单引号里的内容不会被bash扩展 cut 同样可以做到 "\t" 制表符 cut 和 sed 结合同样可以实现 扩展:匿名方法可以有多个,and方法只能有一个 ...
- 软件工程(GZSD2015) 第三次作业提交进度
第三次作业题目请查看这里:软件工程(GZSD2015)第三次作业 开始进入第三次作业提交进度记录中,童鞋们,虚位以待哈... 2015年4月19号 徐镇.尚清丽,C语言 2015年4月21号 毛涛.徐 ...
- HDU 2053 Switch Game
http://acm.hdu.edu.cn/showproblem.php?pid=2053 Problem Description There are many lamps in a line. A ...
- Docker attach
Description Attach local standard input, output, and error streams to a running container Usage dock ...
- Eclipse集成Tomcat报错:java.lang.OutOfMemoryError: PermGen space
Eclipse集成Tomcat报错,使用Spring 4.3 框架,运行一段应用后,控制台报错: Unexpected death of background thread ContainerBack ...