1 条题解

  • 0
    @ 2025-8-24 21:33:30

    自动搬运

    查看原文

    来自洛谷,原作者为

    avatar theb0t
    CNOIer

    搬运于2025-08-24 21:33:30,当前版本为作者最后更新于2025-01-01 16:42:13,作者可能在搬运后再次修改,您可在原文处查看最新版

    自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多

    以下是正文


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

    #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;
    }
    
    • 1

    信息

    ID
    1023
    时间
    1000ms
    内存
    125MiB
    难度
    3
    标签
    递交数
    0
    已通过
    0
    上传者