1 solutions

  • 0
    @ 2024-3-11 23:57:38

    用队列维护 每批人 每次放入队列前 淘汰掉一天前的

    #include<bits/stdc++.h>
    using namespace std;
    int t;
    int n;
    int k;
    int x[300003];
    const int day=86400;
    queue<vector<int>> cache;
    unordered_map<int,int> dao;
    int min_t=-1;
    void solve()
    {
    	scanf("%d %d",&t,&k);
    	if(min_t==-1)
    	{
    		min_t=t;
    	}
    	while(t-min_t>=day&&!cache.empty())
    	{
    		for(int i=1;i<cache.front().size();i++)
    		{
    			dao[cache.front()[i]]-=1;
    		}
    		for(int i=1;i<cache.front().size();i++)
    		{
    			if(dao.count(cache.front()[i])&&dao[cache.front()[i]]<=0)
    			{
    				dao.erase(cache.front()[i]);
    			}
    		}
    		cache.pop();
    		min_t=cache.front()[0];
    	}
        vector<int> qi;
        qi.push_back(t);
    	for(int i=1;i<=k;i++)
    	{
    		int xi;
    		scanf("%d",&xi);
    		qi.push_back(xi);
    		if(!dao.count(xi))
    		{
    			dao[xi]=0;
    		}
    		dao[xi]++;
    	}
    	cache.push(qi);
    	printf("%ld\n",dao.size());
    }
    int main()
    {
    	
    	scanf("%d",&n);
    	while(n--)
    	{
    		solve();
    	}
    }
    

    Information

    ID
    6812
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    9
    Tags
    # Submissions
    148
    Accepted
    9
    Uploaded By