http://acm.hdu.edu.cn/showproblem.php?pid=4122
单调队列。。。
#include<cstdio> #include<cstring> #include<iostream> #define prt(k) cout<<#k"="<<k<<endl; using namespace std; #define ll long long #define inf 1e9 string mon[]={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov" , "Dec"}; int M[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; bool leap(int y) { return y%4==0&&y%100||y%400==0; } struct data { int t,m; }a[7331]; int MON(string s) {for(int i=0;i<12;i++)if(mon[i]==s) return i+1;} int n,m; data q[589222]; int time(int y,int m,int d,int h) { int t=0; for(int i=2000;i<y;i++) if(leap(i)) t+=366; else t+=365; for(int i=1;i<m;i++) if(leap(y)&&i==2) t+=29; else t+=M[i]; t+=d-1; return t*24+h; } int main() { while(cin>>n>>m&&n) { for(int i=0;i<n;i++) { string s; int y,d,h,t; cin>>s>>d>>y>>h>>t; a[i].t=time(y,MON(s),d,h) , a[i].m=t; // prt(a[i].t) prt(a[i].m) } int head=0,tail=-1; ll ans=0; int T,S; cin>>T>>S; int j=0; for(int i=0;i<m;i++) { int x; scanf("%d",&x); while(head<=tail&&q[tail].m+(i-q[tail].t)*S>=x) tail--; q[++tail].m=x,q[tail].t=i; // prt(q[tail].t) prt(q[tail].m) while(j<n&&i==a[j].t) { while(q[head].t+T<i) ++head; ans+=1ll*(q[head].m+(i-q[head].t)*S)*a[j++].m; } } cout<<ans<<endl; } }