BZOJ2501: [usaco2010 Oct]Soda Machine

n<=50000个区间,求哪个点被覆盖区间数量最多,输出这个数量。

差分模板。。然而数组忘开两倍。。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 #include<algorithm>
 5 #include<queue>
 6 //#include<iostream>
 7 using namespace std;
 8 
 9 int n;
10 #define maxn 100011
11 struct eve
12 {
13     int p,v;
14     bool operator < (const eve &b) const
15     {return p<b.p || (p==b.p && v<b.v);}
16 }e[maxn];int le=0;
17 int x,y;
18 int main()
19 {
20     scanf("%d",&n);
21     for (int i=1;i<=n;i++)
22     {
23         scanf("%d%d",&x,&y);
24         e[++le].p=x;e[le].v=1;
25         e[++le].p=y+1;e[le].v=-1;
26     }
27     sort(e+1,e+1+le);
28     int now=0,ans=0;
29     for (int i=1;i<=le;i++)
30     {
31         now+=e[i].v;
32         ans=max(ans,now);
33     }
34     printf("%d
",ans);
35     return 0;
36 }
View Code
原文地址:https://www.cnblogs.com/Blue233333/p/7553275.html