璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:luogup2058
problems
名称海港
题目编号2016 NOIP PJ T3
题目链接luogu.com.cn/…
来源CCF
算法分类队列, 模拟
难易程度一般般

海港

想法

使用队列维护在海港的船,使用桶记录每个国家的人的人数,使用sit[N]记录每艘船人在line上的起点,对于第i艘船,船上人的国别在line[sit[i]]到line[sit[i]+k[i]-1]中。

代码实现

#include<cstdio>
const int N = 1e5+10;
const int M = 1e5*3+10;
int line[M], t[N], k[N], sit[N], tong[N], qu[N];
int ans, cnt, head=1, last;
int main() {
	int n;
	scanf("%d", &n);
	for(int i=1; i<=n; i++) {
		scanf("%d %d", &t[i], &k[i]);
		sit[i] = cnt+1;
		for(int j=0; j<k[i]; j++)
			scanf("%d", &line[++cnt]);
		while(head <= last && t[qu[head]] <= t[i]-86400) {
			for(int j=0; j<k[qu[head]]; j++) {
				int x = sit[qu[head]]+j;
				tong[line[x]]--;
				if(!tong[line[x]])ans--;
			}
			head++;
		}
		for(int j=0; j<k[i]; j++) {
			int x = sit[i]+j;
			tong[line[x]]++;
			if(tong[line[x]]==1)ans++;
		}
		qu[++last] = i;
		printf("%d\n", ans);
	}
	return 0;
}
/app/www/public/data/pages/icpc/problems/luogup2058.txt · 最后更改: 2024/02/01 12:35 由 温婕莺