Files
python/TangDou/LuoGuBook/P2058_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

54 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
int n, t, K, x;
//国籍的桶
unordered_map<int, int> _map;
int res;
struct person {
int nation; //国籍
int t; //到岸时间
};
queue<person> q; //人员队列
person p; //人员实例
int main() {
cin >> n;
//n艘船
for (int i = 1; i <= n; i++) {
//t:每艘船的到岸时间
//k:每艘船的人数
cin >> t >> k;
//k个乘客
for (int j = 1; j <= k; j++) {
cin >> x;
p.nation = x; //国籍
p.t = t; //到岸时间
q.push(p);
//新增加的国籍,结果才加1
if (_map[x] == 0) res++;
//此国籍人数+1
_map[x]++;
}
//维护一个整体,加加减减解决问题,而不是每次都全新计算
while (!q.empty()) {
p = q.front();
//已经超过24小时
if (p.t + 86400 <= t) {
//相应国籍人数--
_map[p.nation]--;
//如果减了就没有了,需要结果-1
if (_map[p.nation] == 0) res--;
//弹出
q.pop();
} else break;//因为数据保证是ti是由小到大的,所以可以减枝
}
//输出每艘船结果
cout << res << endl;
}
return 0;
}