为啥 开O2超时 不开反而过了
查看原帖
为啥 开O2超时 不开反而过了
814884
aser12楼主2022/11/22 01:47
#include <bits/stdc++.h>

using namespace std;

const int N = 86400,M = 1e5+10;

int q[N + 10];
int tim[M];			//时间
unordered_map<int,unordered_map<int,int>> a;
unordered_map<int,int> b;
int n,t,k,x;

    
int main(){
	scanf("%d",&n);
	int hh = 0, tt = -1; 
	for(int i = 1; i <= n; i++){
		
		scanf("%d%d",&tim[i],&k);
		while(k--){
			scanf("%d",&x);
			a[i][x]++;  //记录当前的国籍 
		}
		 
		// 维护滑动窗口,窗口中的值要在一天之内
		while(hh <= tt && tim[i] - tim[q[hh]] >= N){
			for(auto [j,v]: a[q[hh]]){  //删除hh 的所有国籍
				b[j] = b[j] - v;
				if(b[j] == 0) b.erase(j);
			}
			hh++;
		}
		
		// 队尾加入 
		for(auto [j,v]: a[i]) b[j] = b[j] + v; 
		q[++tt] = i;
		
		//输出当前滑动窗口的国籍数量 
		cout << b.size() << endl; 
	}
}

2022/11/22 01:47
加载中...