璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:luogup9094
problems
名称Mieszanie kolorów
题目编号P9094
题目链接luogu.com.cn/…
来源Luogu
算法分类前缀和, 差分
难易程度容易

Mieszanie kolorów

想法

对每种颜色分别进行区间加操作(差分),只统计有黄色有蓝色没有红色的个数。

代码实现

#include<cstdio>
const int N = 1e6+10;
int c[N][4];
int main() {
	int n, m, x, y, type, cnt=0;
	scanf("%d %d", &n, &m);
	for(int i=1; i<=m; i++) {
		scanf("%d %d %d", &x, &y, &type);
		c[x][type]++;
		c[y+1][type]--;
	}
	for(int i=1; i<=n; i++) {
		c[i][1] += c[i-1][1];
		c[i][2] += c[i-1][2];
		c[i][3] += c[i-1][3];
		if(c[i][1]&&c[i][2]&&(!c[i][3]))
			cnt++;
	}
	printf("%d", cnt);
	return 0;
}
/app/www/public/data/pages/icpc/problems/luogup9094.txt · 最后更改: 2024/02/17 11:46 由 温婕莺