70分TLE
查看原帖
70分TLE
1367432
jcs_pp楼主2024/11/25 21:09

有没有可以优化的地方,时间复杂度太高啦!

#include <bits/stdc++.h>
using namespace std;
struct SHIP
{
	int t;
	int k;
	int s[1010];
}a[100010];
int hh,tt;
int n;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[tt].t>>a[tt].k;
		for(int j=1;j<=a[tt].k;j++) cin>>a[tt].s[j];
		tt++;
		while(a[tt-1].t-a[hh].t>=86400) hh++;
		int cnt=0;
		int js[300010]={0};
		for(int j=hh;j<tt;j++)
		{
			for(int x=1;x<=a[j].k;x++)
			{
				int y=a[j].s[x];
				js[y]++;
				if(js[y]==1) cnt++;
			}
		}
		cout<<cnt<<'\n';
	}
    return 0;
}
2024/11/25 21:09
加载中...