码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 1000C Covered Points Count

时间:2018-07-07 17:36:25      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:queue   分享图片   efi   stream   ref   get   int   contest   lld   

C. Covered Points Count
题目大意:有n条线段,问有多少个点被i条线段覆盖(i=1~n)。
很常见的线段覆盖套路题QAQ。
坐标排序后把左端点当做+1,右端点当做-1,扫一遍统计答案即可。
但是记得开ll,数组大小开双倍。

技术分享图片
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cmath>
 5 #include <queue>
 6 #define ll long long
 7 #define out(a) printf("%lld ",a)
 8 using namespace std;
 9 int n,tot;
10 ll ans[200050];
11 ll l,r,now=0;
12 ll read()
13 {
14     ll s=0,t=1; char c;
15     while (c<0||c>9){if (c==-) t=-1; c=getchar();}
16     while (c>=0&&c<=9){s=s*10+c-0; c=getchar();}
17     return s*t;
18 } 
19 struct dist
20 {
21     ll num,h;
22 }a[400050];
23 bool cmp(dist a,dist b)
24 {
25     return a.num==b.num?a.h<b.h:a.num<b.num;
26 }
27 int main()
28 {
29     n=read(); now=0;
30     for (int i=1;i<=n;i++) {
31       l=read(),r=read();
32       a[++tot].num=l,a[tot].h=1;
33       a[++tot].num=r+1,a[tot].h=-1;
34     }
35     sort(a+1,a+tot+1,cmp); 
36     for (int i=1;i<=tot;i++) {
37       ans[now]+=a[i].num-a[i-1].num;
38       now+=a[i].h;
39     }
40     for (int i=1;i<=n;i++)
41       out(ans[i]);
42     return 0;
43 }
View Code

 

Codeforces 1000C Covered Points Count

标签:queue   分享图片   efi   stream   ref   get   int   contest   lld   

原文地址:https://www.cnblogs.com/Kaleidoscope233/p/9277277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!