7-23 扫码抗疫情

#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<map>
using namespace std;
struct students{
	string s,ss;
	int h,m,sec,t;
}a[10005];
int n,k,ans,cnt;
bool cmp(const students &x,const students &y)
{
	return x.t<y.t;
}
bool cmp0(const students &x,const students &y)
{
	return x.s<y.s;
}
map<string,bool>q;
map<string,int>last; 
map<string,int>ti;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].s;
		scanf("%d:%d:%d",&a[i].h,&a[i].m,&a[i].sec);
		cin>>a[i].ss;
		a[i].t=a[i].h*3600+a[i].m*60+a[i].sec;
	}
	sort(a+1,a+1+n,cmp);
	cnt=n;
	for(int i=1;i<=n;i++)
	{						
		if(a[i].ss=="out")
		{
			if(q[a[i].s])
			{
				q[a[i].s]=0;
				ans--;
				ti[a[i].s]+=a[i].t-a[last[a[i].s]].t;
				last[a[i].s]=0;
			}
			else{
				a[i].t=1e9;
				cnt--;
			}
		}
		else{
			if(q[a[i].s])
			{
				a[last[a[i].s]].t=1e9;
				cnt--;
			}
			else{
				q[a[i].s]=1;
				ans++;
			}
			last[a[i].s]=i;
		}
	}
	map<string,bool>::iterator it;
	for(it=q.begin();it!=q.end();it++)
	{
		if(it->second==1)
		{
			a[last[it->first]].t=1e9;
			cnt--;
		}
	}
	sort(a+1,a+1+n,cmp);
	int j=1;
	ans=0;
	for(int i=1,h,m,s;i<=k;i++)
	{
		scanf("%d:%d:%d",&h,&m,&s);
		int t=h*3600+m*60+s;
		while(t>=a[j].t&&j<=n)
		{
			if(a[j].ss=="in")
			ans++;
			else
			ans--;
			j++;
		}
		cout<<ans<<endl;
	}
	queue<string>q0; 
	int mx=0;
	sort(a+1,a+1+n,cmp0);
	for(int i=1;i<=n;i++)
	{
		if(a[i].s!=a[i-1].s)
		{
			if(ti[a[i].s]==mx)
				q0.push(a[i].s);
			if(ti[a[i].s]>mx)
			{
				mx=ti[a[i].s];
				while(!q0.empty())
				q0.pop();
				q0.push(a[i].s);
			}
		}
	}
	while(!q0.empty())
	{
		string ac=q0.front();
		q0.pop();
		cout<<ac<<' ';
	}
	int h0=mx/3600;
	mx%=3600;
	int m0=mx/60;
	mx%=60;
	printf("%02d:%02d:%02d",h0,m0,mx);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哈希表扁豆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值