BZOJ 4868 SHOI2017 期末考试

题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4868

 

题意概述:抱歉今天的我比较懒......

 

分析:

  我都不知道当时我的大脑发生了什么为什么没有把这个弱智题切掉ORZ

  假设我们最后需要在第i天完成所有的批改,可以在预处理过之后O(1)算出答案。

  不难发现这个问题的最优解具有单峰函数的性质,可以三分答案。

  所以这个sb题当时为什么没有做出来?!

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<set>
 9 #include<map>
10 #include<vector>
11 #include<cctype>
12 using namespace std;
13 const int maxn=100005;
14 typedef long long LL;
15 
16 int A,B,N,M,t[maxn],b[maxn],c[maxn];
17 LL C,t1[maxn],t2[maxn],s[maxn];
18 
19 void _scanf(int &x)
20 {
21     x=0;
22     char c=getchar();
23     while(c<'0'||c>'9') c=getchar();
24     while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
25 }
26 void data_in()
27 {
28     _scanf(A);_scanf(B);cin>>C;_scanf(N);_scanf(M);
29     for(int i=1;i<=N;i++) _scanf(t[i]);
30     for(int i=1;i<=M;i++) _scanf(b[i]);
31 }
32 LL calc(int p){
33     LL re=s[p]*C,rest=t2[p];
34     if(A<B){
35         re+=min(rest,t1[p])*A;
36         rest-=min(rest,t1[p]);
37     }
38     re+=rest*B;
39     return re;
40 }
41 void msort(int *a,int l,int r)
42 {
43     int m=0,cnt=l;
44     for(int i=l;i<=r;i++)
45         if(a[i]>m) m=a[i];
46     for(int i=0;i<=m;i++) c[i]=0;
47     for(int i=l;i<=r;i++) c[a[i]]++;
48     for(int i=0;i<=m;i++)
49         while(c[i]) a[cnt++]=i,c[i]--;
50 }
51 void work()
52 {
53     msort(t,1,N);
54     msort(b,1,M);
55     int cnt=1;
56     for(int i=1;i<=max(t[N],b[M]);i++){
57         while(t[cnt]<i&&cnt<=N) cnt++;
58         s[i]=s[i-1]+cnt-1;
59     }
60     cnt=1;
61     for(int i=1;i<=b[M];i++){
62         while(b[cnt]<i&&cnt<=M) cnt++;
63         t1[i]=t1[i-1]+cnt-1;
64     }
65     cnt=M;
66     for(int i=b[M];i>=1;i--){
67         while(b[cnt]>i&&cnt>=1) cnt--;
68         t2[i]=t2[i+1]+M-cnt;
69     }
70     if(C==1e16) cout<<calc(t[1])<<'\n';
71     else{
72         int L=1,R=b[M]+1,m1,m2,d;
73         while(R-L>5){
74             d=(R-L)/3,m1=L+d,m2=R-d;
75             if(calc(m1)<calc(m2)) R=m2;
76             else L=m1+1;
77         }
78         LL ans=calc(L);
79         for(int i=L+1;i<R;i++) ans=min(ans,calc(i));
80         cout<<ans<<'\n';
81     }
82 }
83 int main()
84 {
85     data_in();
86     work();
87     return 0;
88 }
View Code

 

posted @ 2018-04-06 17:57  KKKorange  阅读(199)  评论(0编辑  收藏  举报