专栏文章

题解:P2058 [NOIP2016 普及组] 海港

P2058题解参与者 19已保存评论 20

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
20 条
当前快照
1 份
快照标识符
@miqlwvrk
此快照首次捕获于
2025/12/04 06:56
3 个月前
此快照最后确认于
2025/12/04 06:56
3 个月前
查看原文
使用队列存储每一个船上的每一个人,当一条新的船到达时,把之前超时的人弹出队列,然后输出答案。
CPP
#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;
}

评论

20 条评论,欢迎与作者交流。

正在加载评论...