2533: 【普及/提高-】【P2058】海港

内存限制:128 MB 时间限制:2.000 S
评测方式:文本比较 命题人:
提交:11 解决:3

题目描述

小 K 是一个海港的海关工作人员,每天都有许多船只到达海港,船上通常有很多来自不同国家的乘客。

小 K 对这些到达海港的船只非常感兴趣,他按照时间记录下了到达海港的每一艘船只情况;对于第 lns="http://www.w3.org/1998/Math/MathML"> 艘到达的船,他记录了这艘船到达的时间 lns="http://www.w3.org/1998/Math/MathML"> (单位:秒),船上的乘客数 lns="http://www.w3.org/1998/Math/MathML">,以及每名乘客的国籍 lns="http://www.w3.org/1998/Math/MathML">,1,,2,,,

小K统计了 lns="http://www.w3.org/1998/Math/MathML"> 艘船的信息,希望你帮忙计算出以每一艘船到达时间为止的 lns="http://www.w3.org/1998/Math/MathML">24 小时(lns="http://www.w3.org/1998/Math/MathML">24 小时 lns="http://www.w3.org/1998/Math/MathML">=86400 秒)内所有乘船到达的乘客来自多少个不同的国家。

形式化地讲,你需要计算 lns="http://www.w3.org/1998/Math/MathML"> 条信息。对于输出的第 lns="http://www.w3.org/1998/Math/MathML"> 条信息,你需要统计满足 lns="http://www.w3.org/1998/Math/MathML">86400< 的船只 lns="http://www.w3.org/1998/Math/MathML">,在所有的 lns="http://www.w3.org/1998/Math/MathML">, 中,总共有多少个不同的数。

输入

第一行输入一个正整数 lns="http://www.w3.org/1998/Math/MathML">,表示小 K 统计了 lns="http://www.w3.org/1998/Math/MathML"> 艘船的信息。

接下来 lns="http://www.w3.org/1998/Math/MathML"> 行,每行描述一艘船的信息:前两个整数 lns="http://www.w3.org/1998/Math/MathML"> 和 lns="http://www.w3.org/1998/Math/MathML"> 分别表示这艘船到达海港的时间和船上的乘客数量,接下来 lns="http://www.w3.org/1998/Math/MathML"> 个整数 lns="http://www.w3.org/1998/Math/MathML">, 表示船上乘客的国籍。

保证输入的 lns="http://www.w3.org/1998/Math/MathML"> 是递增的,单位是秒;表示从小K第一次上班开始计时,这艘船在第 lns="http://www.w3.org/1998/Math/MathML"> 秒到达海港。

保证 lns="http://www.w3.org/1998/Math/MathML">1105lns="http://www.w3.org/1998/Math/MathML">3×105 ,lns="http://www.w3.org/1998/Math/MathML">1,105, lns="http://www.w3.org/1998/Math/MathML">11109

其中 lns="http://www.w3.org/1998/Math/MathML"> 表示所有的 lns="http://www.w3.org/1998/Math/MathML"> 的和。

输出

输出 lns="http://www.w3.org/1998/Math/MathML"> 行,第 lns="http://www.w3.org/1998/Math/MathML"> 行输出一个整数表示第 lns="http://www.w3.org/1998/Math/MathML"> 艘船到达后的统计信息。

样例输入 复制

3
1 4 4 1 2 2
2 2 2 3
10 1 3

样例输出 复制

3
4
4

提示

【样例解释 1】

第一艘船在第 lns="http://www.w3.org/1998/Math/MathML">1 秒到达海港,最近 lns="http://www.w3.org/1998/Math/MathML">24 小时到达的船是第一艘船,共有 lns="http://www.w3.org/1998/Math/MathML">4 个乘客,分别是来自国家 lns="http://www.w3.org/1998/Math/MathML">4,1,2,2,共来自 lns="http://www.w3.org/1998/Math/MathML">3 个不同的国家;

第二艘船在第 lns="http://www.w3.org/1998/Math/MathML">2 秒到达海港,最近 lns="http://www.w3.org/1998/Math/MathML">24 小时到达的船是第一艘船和第二艘船,共有 lns="http://www.w3.org/1998/Math/MathML">4+2=6 个乘客,分别是来自国家 lns="http://www.w3.org/1998/Math/MathML">4,1,2,2,2,3,共来自 lns="http://www.w3.org/1998/Math/MathML">4 个不同的国家;

第三艘船在第 lns="http://www.w3.org/1998/Math/MathML">10 秒到达海港,最近 lns="http://www.w3.org/1998/Math/MathML">24 小时到达的船是第一艘船、第二艘船和第三艘船,共有 lns="http://www.w3.org/1998/Math/MathML">4+2+1=7 个乘客,分别是来自国家 lns="http://www.w3.org/1998/Math/MathML">4,1,2,2,2,3,3,共来自 lns="http://www.w3.org/1998/Math/MathML">4 个不同的国家。

样例输入2:

4
1 4 1 2 2 3
3 2 2 3
86401 2 3 4
86402 1 5
样例输出2:

3
3
3
4

【样例解释 2】

第一艘船在第 lns="http://www.w3.org/1998/Math/MathML">1 秒到达海港,最近 lns="http://www.w3.org/1998/Math/MathML">24 小时到达的船是第一艘船,共有 lns="http://www.w3.org/1998/Math/MathML">4 个乘客,分别是来自国家 lns="http://www.w3.org/1998/Math/MathML">1,2,2,3,共来自 lns="http://www.w3.org/1998/Math/MathML">3 个不同的国家。

第二艘船在第 lns="http://www.w3.org/1998/Math/MathML">3 秒到达海港,最近 lns="http://www.w3.org/1998/Math/MathML">24 小时到达的船是第一艘船和第二艘船,共有 lns="http://www.w3.org/1998/Math/MathML">4+2=6 个乘客,分别是来自国家 lns="http://www.w3.org/1998/Math/MathML">1,2,2,3,2,3,共来自 lns="http://www.w3.org/1998/Math/MathML">3 个不同的国家。

第三艘船在第 lns="http://www.w3.org/1998/Math/MathML">86401 秒到达海港,最近 lns="http://www.w3.org/1998/Math/MathML">24 小时到达的船是第二艘船和第三艘船,共有 lns="http://www.w3.org/1998/Math/MathML">2+2=4 个乘客,分别是来自国家 lns="http://www.w3.org/1998/Math/MathML">2,3,3,4,共来自 lns="http://www.w3.org/1998/Math/MathML">3 个不同的国家。

第四艘船在第 lns="http://www.w3.org/1998/Math/MathML">86402 秒到达海港,最近 lns="http://www.w3.org/1998/Math/MathML">24 小时到达的船是第二艘船、第三艘船和第四艘船,共有 lns="http://www.w3.org/1998/Math/MathML">2+2+1=5 个乘客,分别是来自国家 lns="http://www.w3.org/1998/Math/MathML">2,3,3,4,5,共来自 lns="http://www.w3.org/1998/Math/MathML">4个 不同的国家。


#include<bits/stdc++.h>
using namespace std;
struct people{
	int t,x;
};
int ct[100005] = {0},n,t,k,tmp,ans = 0;
int main(){
    queue<people> q;
    people p;
    cin >> n;
    for (int i=0;i < n; i++) {
    	cin >> t >> k;
		for(int j = 0;j < k; j++) {
			cin >> tmp;
			if(ct[tmp] == 0) ans++;
			ct[tmp]++;
			q.push({t,tmp});
		}
		p = q.front();
		while(t - p.t>=86400){
			ct[p.x]--;
			if(ct[p.x] == 0) ans--;
			q.pop();
			p = q.front();
		}
		cout << ans <<endl; 
	}
	return 0;
}