You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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