Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2596 Accepted Submission(s): 619
只需要静态查询最小值就可以了。
有一些细节要处理。
1 /* *********************************************** 2 Author :kuangbin 3 Created Time :2013-11-8 9:59:19 4 File Name :E:\2013ACM\专题强化训练\区域赛\2011福州\B.cpp 5 ************************************************ */ 6 7 #include <stdio.h> 8 #include <string.h> 9 #include <iostream> 10 #include <algorithm> 11 #include <vector> 12 #include <queue> 13 #include <set> 14 #include <map> 15 #include <string> 16 #include <math.h> 17 #include <stdlib.h> 18 #include <time.h> 19 using namespace std; 20 21 22 int getmonth(char s[]) 23 { 24 if(strcmp(s,"Jan") == 0) return 1; 25 if(strcmp(s,"Feb") == 0) return 2; 26 if(strcmp(s,"Mar") == 0) return 3; 27 if(strcmp(s,"Apr") == 0) return 4; 28 if(strcmp(s,"May") == 0) return 5; 29 if(strcmp(s,"Jun") == 0) return 6; 30 if(strcmp(s,"Jul") == 0) return 7; 31 if(strcmp(s,"Aug") == 0) return 8; 32 if(strcmp(s,"Sep") == 0) return 9; 33 if(strcmp(s,"Oct") == 0) return 10; 34 if(strcmp(s,"Nov") == 0) return 11; 35 if(strcmp(s,"Dec") == 0) return 12; 36 } 37 int days[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; 38 bool isleap(int y) 39 { 40 if(y % 400 == 0 || (y % 100 != 0 && y%4 == 0))return true; 41 else return false; 42 } 43 struct Node 44 { 45 char mon[10]; 46 int d,y,h; 47 int R; 48 int index; 49 void input() 50 { 51 scanf("%s%d%d%d%d",mon,&d,&y,&h,&R); 52 if(y < 2000) 53 { 54 index = -1; 55 return; 56 } 57 index = 0; 58 for(int i = 2000;i < y;i++) 59 { 60 if(isleap(i)) index += 366*24; 61 else index += 365*24; 62 } 63 for(int i = 1;i < getmonth(mon);i++) 64 index += days[i]*24; 65 if(isleap(y) && getmonth(mon) > 2)index += 24; 66 index += (d-1)*24; 67 index += h+1; 68 } 69 }; 70 71 const int MAXN = 100010; 72 long long dp[MAXN][20]; 73 long long b[MAXN]; 74 int mm[MAXN]; 75 void initRMQ(int n) 76 { 77 mm[0] = -1; 78 for(int i = 1;i <= n;i++) 79 { 80 mm[i] = ((i&(i-1)) == 0)?mm[i-1]+1:mm[i-1]; 81 dp[i][0] = b[i]; 82 } 83 for(int j = 1;j <= mm[n];j++) 84 for(int i = 1;i + (1<<j) - 1 <= n;i++) 85 dp[i][j] = min(dp[i][j-1],dp[i+(1<<(j-1))][j-1]); 86 } 87 long long rmq(int x,int y) 88 { 89 int k = mm[y-x+1]; 90 return min(dp[x][k],dp[y - (1<<k) + 1][k]); 91 } 92 93 Node node[3000]; 94 95 int main() 96 { 97 //freopen("in.txt","r",stdin); 98 //freopen("out.txt","w",stdout); 99 int n,m; 100 int T,S; 101 while(scanf("%d%d",&n,&m) == 2) 102 { 103 if(n == 0 && m == 0)break; 104 for(int i = 0;i < n;i++) 105 node[i].input(); 106 scanf("%d%d",&T,&S); 107 for(int i = 1;i <= m;i++) 108 { 109 scanf("%I64d",&b[i]); 110 b[i] += (m-i)*S; 111 } 112 initRMQ(m); 113 long long ans = 0; 114 for(int i = 0;i < n;i++) 115 { 116 if(node[i].index < 0 || node[i].index > m)continue; 117 long long tmp = rmq(max(1,node[i].index - T),node[i].index); 118 tmp -= (m - node[i].index)*S; 119 ans += tmp * node[i].R; 120 } 121 cout<<ans<<endl; 122 } 123 return 0; 124 }