CF845C Two TVs 题解

分析

离散化,然后如果某个时间同时存在至少 \(3\) 个未结束的节目,那么无解。

差分即可。

CODE

#include<bits/stdc++.h>
using namespace std;
#define int long long
int read() {
	int a=0, f=1; char c=getchar();
	while(!isdigit(c)) {
		if(c=='-') f=-1;
		c=getchar();
	}
	while(isdigit(c)) a=a*10+c-'0', c=getchar();
	return a*f;
}
const int N=2e5+5;
int n, m, c[2*N], d[2*N];
pair<int,int> p[N];
#define x first
#define y second
signed main() {
	n=read();
	for(int i=1;i<=n;++i) {
		p[i].x=read(), p[i].y=read();
		c[++m]=p[i].x, c[++m]=p[i].y;
	}
	sort(c+1,c+m+1);
	m=unique(c+1,c+m+1)-c-1;
	for(int i=1;i<=n;++i) {
		p[i].x=lower_bound(c+1,c+m+1,p[i].x)-c;
		p[i].y=lower_bound(c+1,c+m+1,p[i].y)-c;
	}
	// sort(p+1,p+n+1);
	for(int i=1;i<=n;++i) {
		++d[p[i].x], --d[p[i].y+1];
	}
	int cc=0;
	for(int i=1;i<=m;++i) {
		cc+=d[i];
		if(cc>=3) { puts("NO"); return 0; }
	}
	puts("YES");
}

CF845C Two TVs 题解
https://yozora0908.github.io/2022/cf845c-solution/
作者
yozora0908
发布于
2022年10月2日
许可协议