solution
桶加队列。开一个桶数组 记录 小时内每个国籍的人数,在读入时,若某个国籍的人刚好为 ,说明是新的国籍,答案加一。对于二十四小时这个条件,可以用队列维护,队首是最先入队的,让队首满足二十四小时内即可。若队首不满足 数组减一,若 数组减后为 ,说明减少了一种国籍,答案减一。
code
#include<bits/stdc++.h>
using namespace std;
int n, ans, num[100005];
struct node{ int x, t; } h;
queue<node> q;
int main(){
cin >> n;
for(int i=1, t, k; i<=n; i++){
cin >> t >> k;
for(int j=1, x; j<=k; j++)
cin >> x,
q.push({x, t}),
ans+=(++num[x]==1);
for (h=q.front(); q.size()&&h.t+86400<=t; q.pop(), h=q.front())
ans-=(--num[h.x]==0);
cout << ans << '\n';
}
return 0;
}