【题解】P2058

使用队列存储每一个船上的每一个人,当一条新的船到达时,把之前超时的人弹出队列,然后输出答案。

#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct node
{
	int timee,country;
}q[300005];
int cnt[100005],ans;
int head,tail;
int main()
{
	//freopen("a.txt","r",stdin);
	int T;
	cin>>T;
	while(T--)
	{
		int t,k;
		cin>>t>>k;
		for(int i=1;i<=k;i++)
		{
			int x;
			cin>>x;
			q[++tail]={t,x};
			cnt[x]++;
			if(cnt[x]==1) ans++;
		}
		while(head<tail&&t-q[head].timee>=86400)
		{
			cnt[q[head].country]--;
			if(cnt[q[head].country]==0) ans--;
			head++;
		}
		cout<<ans<<'\n';
	}
    return 0;
}
posted @ 2025-01-03 19:46  日月月  阅读(21)  评论(2编辑  收藏  举报