题目链接
看题目每个数据都挺大的,再加上这个诡异的要求,刚看到还是有点蒙的.有一会才看明白啥意思,选了双端队列来做.(主要是对数据范围判断失误了,数组+双指针应该也是能过的)
这道题不仅卡时间,还卡空间,标记数组不能开太多要不会炸;刚开始按船为单位写,到查重的时候可以说是举步维艰,做题的时候还疑惑人数会不会太多然后炸内存,用双端队列这种动态类型直接存人头,再根据时间更新答案和标记数组,成功a题.
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct head
{
int tm;
int ct;
};
deque<head> d;
int n;
int ans = 0;
int flag[N];
int main()
{
cin >> n;
for(int i = 0 ; i < n ; i++)
{
int tm,sum;
cin >> tm >> sum;
for(int j = 0 ; j < sum ; j++)
{
head h;
int ct;
h.tm = tm;
cin >> ct;
h.ct = ct;
if(!flag[ct])
ans++;
flag[ct]++;
d.push_back(h);
}
while(d.back().tm - d.front().tm >= 86400)
{
flag[d.front().ct]--;
if(!flag[d.front().ct])
ans--;
d.pop_front();
}
cout << ans << endl;
}
return 0;
}