The meaning of problems:
Enter two positive integers N and K (N <= 1e4, K <= 8e4), followed by N input data lines each comprising a string representation of three license plate number, the current time, the status of entering or leaving. Then enter K times inquiry, output current number of vehicles stuck in school. The last line of output a total residence time of the longest license plate number (ascending lexicographical output) and total residence time.
AAAAAccepted code:
// Because the day only 86,400 seconds, so you can use a car array of statistics when the vehicle enters the dwell time at +1 time, departure time -1. Then again a sweeping array sum, sum [i] = sum [i-1] + car [i], to indicate the current time how many vehicles are still staying on campus.
1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 map<string,int>mp; 5 vector<pair<string,int> >v[10007]; 6 int sum[100007],car[100007]; 7 int t[10007]; 8 map<int,string>id; 9 vector<string>name; 10 int a[17]; 11 void clear(string&s){ 12 string ss; 13 swap(s,ss); 14 } 15 int main(){ 16 ios::sync_with_stdio(false); 17 cin.tie(NULL); 18 cout.tie(NULL); 19 int n,k; 20 cin>>n>>k; 21 int cnt=0; 22 for(int i=1;i<=n;++i){ 23 string s; 24 cin>>s; 25 string t; 26 cin>>t; 27 string f; 28 cin>>f; 29 if(!mp[s]) 30 mp[s]=++cnt; 31 id[mp[s]]=s; 32 int flag=0; 33 if(f[0]=='i') 34 flag=1; 35 v[mp[s]].push_back({t,flag}); 36 } 37 for(int i=1;i<=cnt;++i){ 38 sort(v[i].begin(),v[i].end()); 39 string now; 40 int flag=0; 41 for(int j=0;j<v[i].size();++j){ 42 if(v[i][j].second==1){ 43 now=v[i][j].first; 44 flag=1; 45 } 46 else{ 47 if(flag){ 48 string tamp=v[i][j].first; 49 int start=(now[0]-'0')*36000+(now[1]-'0')*3600+(now[3]-'0')*600+(now[4]-'0')*60+(now[6]-'0')*10+(now[7]-' 0 ' ); 50 int over = (full view [ 0 ] - ' 0 ' ) * 36000 + (full view [ 1 ] - ' 0 ' ) * 3600 + (full view [ 3 ] - ' 0 ' ) * 600 + (full view [ 4 ] - ' 0 ' ) * 60 + (full view [ 6 ] - ' 0 ' ) * 10 + (full view [ 7 ] - ' 0 ' ); 51 ++car[start]; 52 --car[over]; 53 flag=0; 54 clear(now); 55 t[i]+=over-start; 56 } 57 } 58 } 59 } 60 sum[0]+=car[0]; 61 for(int i=0;i<86400;++i) 62 sum[i]=sum[i-1]+car[i]; 63 for(int i=1;i<=k;++i){ 64 string tamp; 65 cin>>tamp; 66 int tt=(tamp[0]-'0')*36000+(tamp[1]-'0')*3600+(tamp[3]-'0')*600+(tamp[4]-'0')*60+(tamp[6]-'0')*10+(tamp[7]-'0'); 67 cout<<sum[tt]<<"\n"; 68 } 69 int mx=0; 70 for(int i=1;i<=cnt;++i) 71 mx=max(mx,t[i]); 72 for(int i=1;i<=cnt;++i) 73 if(mx==t[i]) 74 name.push_back(id[i]); 75 sort(name.begin(),name.end()); 76 for(int i=0;i<name.size();++i) 77 cout<<name[i]<<" "; 78 a[1]=mx/36000; 79 mx%=36000; 80 a[2]=mx/3600; 81 mx%=3600; 82 a[3]=mx/600; 83 mx%=600; 84 a[4]=mx/60; 85 mx%=60; 86 a[5]=mx/10; 87 mx%=10; 88 a[6]=mx; 89 cout<<a[1]<<a[2]<<":"<<a[3]<<a[4]<<":"<<a[5]<<a[6]; 90 return 0; 91 }