队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书

题解:看到这题就想到了 poetize 的封印之门,然后就用差分序列水过了。。。不过把线段排序也可以一遍扫出来?

代码:

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<iostream>
 7 #include<vector>
 8 #include<map>
 9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 250000
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=(n);i++)
19 #define for1(i,n) for(int i=1;i<=(n);i++)
20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
22 #define mod 1000000007
23 using namespace std;
24 inline int read()
25 {
26     int x=0,f=1;char ch=getchar();
27     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
28     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
29     return x*f;
30 }
31 ll n,tot,a[maxn],b[maxn],c[maxn],d[maxn],s[maxn];
32 inline bool cmp(int x,int y){return a[x]<a[y];}
33 int main()
34 {
35     //freopen("input.txt","r",stdin);
36     //freopen("output.txt","w",stdout);
37     n=read();
38     for1(i,n)a[i]=read(),a[n+i]=read();
39     for1(i,2*n)c[i]=i;
40     sort(c+1,c+2*n+1,cmp);
41     tot=0;
42     for1(i,2*n)
43     {
44         if(i==1||a[c[i]]!=a[c[i-1]])tot++;
45         b[c[i]]=tot;d[tot]=a[c[i]];
46     }
47     for1(i,n)
48     {
49         s[b[i]]++;s[b[n+i]+1]--;
50     }
51     for1(i,tot)s[i]+=s[i-1];
52     int ans=0;
53     for1(i,tot)if(s[i]*d[i]>d[ans]*s[ans])ans=i;
54     printf("%lld\n",d[ans]*s[ans]);
55     return 0;
56 }
View Code

 

posted @ 2014-11-02 13:19  ZYF-ZYF  Views(259)  Comments(0Edit  收藏  举报