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.

44 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;
const int N = 100010;
int n;
int t[N];
vector<int> q[N];
int s[N];
int main() {
// 加快读入
ios::sync_with_stdio(false), cin.tie(0);
cin >> n; // n 艘船的信息
for (int i = 0; i < n; i++) {
int cnt;
cin >> t[i] >> cnt; // 这艘船到达海港的时间和船上的乘客数量
while (cnt--) {
int x;
cin >> x; // 船上乘客的国籍
q[i].push_back(x); // i号船上有多少个乘客都是哪个国家的
}
}
// 经典快慢指针模板
// ① i 快指针j 慢指针
for (int i = 0, j = 0, c = 0; i < n; i++) { // 滑动窗口,双指针,遍历每艘船
for (auto x : q[i]) // 遍历每个乘客
if (++s[x] == 1) // 如果x国家原来是0个乘客现在变成1了就是多了一个国家
c++;
// ② while 区间 [i, j] 不满足条件
while (t[i] - t[j] >= 86400) { // 每一艘船到达时间为止的 24 小时24 小时 =86400 秒)
for (auto x : q[j]) // 遍历每个乘客
if (--s[x] == 0) // 如果x国家原来有1个乘客现在变成0了就少了一个国家
c--;
j++;
}
// 输出国家数量
printf("%d\n", c);
}
return 0;
}