40分求助,用的unordered_map和queue
查看原帖
40分求助,用的unordered_map和queue
874984
ho33楼主2023/1/3 16:36
#include<iostream>
#include<vector>
#include<unordered_map>
#include<queue>
using namespace std;
struct node
{
	int time;
	int type;
};
int main()
{
	//int gj[100001] = { 0 };
	int n;
	int t, k;
	int temp;
	struct node zcs;
	unordered_map<int, int>gj;
	int count = 0;
	queue<node>q;
	vector<int>p;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> t >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> temp;
			/*if (!gj[temp])
			{
				count++;
			}*/
			if (gj.find(temp) == gj.end())
			{
				count++;
				gj.insert(pair<int, int>{temp, 0});
			}
			gj.find(temp)->second++;
			zcs.time = t;
			zcs.type = temp;
			q.push(zcs);
		}
		while (t - q.front().time >= 86400)
		{
			gj.find(q.front().type)->second--;
			if (gj.find(q.front().type)->second == 0)
			{
				count--;
			}
			q.pop();
		}
		p.push_back(count);
	}
	for (int i = 0; i < p.size(); i++)
	{
		cout << p[i] << endl;
	}
}
2023/1/3 16:36
加载中...