xjtuoj 1264:视频质量

题目来源

题目分为两个任务,\(X\)是金典的区间全覆盖问题,\(Y\)是woshidashabi
注意区间是左闭右开所以判断取最远覆盖的时候用\(<\)

#include<bits/stdc++.h>
#define F(i,n,m) for(ll i=n;i<m;i++)
#define itn int
#define f(i,n,m) for(ll i=n;i>m;i--)
//#define test
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
struct PP {
	ll lp,rp;
} fc[200005];
inline ll read() {
	ll num = 0;
	char c;
	bool flag = false;
	while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
	if (c == '-') flag = true;
	else
		num = c - '0';
	while (isdigit(c = getchar()))
		num = num * 10 + c - '0';
	return (flag ? -1 : 1) * num;
}
bool cmp(PP a,PP b) {
	if(a.lp==b.lp) return a.rp>b.rp;
	return a.lp<b.lp;
}
int main() {
	std::ios::sync_with_stdio(false);
	ll n,m;
	n=read();
	m=read();
	F(i,0,n) {
		fc[i].lp=read();
		fc[i].rp=read();
	}
	sort(fc,fc+n,cmp);
#ifdef test
	F(i,0,n) cout<<endl<<fc[i].lp<<" "<<fc[i].rp<<endl;
#endif
	ll la,nt;
	ll ans=0;
	la=nt=0;
	F(i,0,n) {
		if(la<fc[i].lp) {//左闭右开,找到新的起始点及其最远距离,并且选取上一个起始点计入答案
			la=nt;
			ans++;
		}
		nt=max(nt,fc[i].rp);//更新范围内最远距离
		if(nt==m) {//如果这次最远距离已经选到边界,直接退出更快
			ans++;
			break;
		}
#ifdef test
		cout<<ans<<" "<<i<<" "<<la<<endl;
#endif
	}
	ll sna=0,san=0;
	f(i,n-1,-1) {
		if(fc[i].rp==m) sna++;
		if(fc[i].lp==0) san++;
	}
	cout<<ans<<" "<<max(n-san+1,n-sna+1);
	return 0;
}


然后是任务2,考虑极端情况即选取的\(Y-1\)个观众都没有看第一或最后一个视频,故答案取\(n-min(num(a_0),num(a_n))+1\)

posted @ 2022-04-21 12:09  FPICZEIT  阅读(20)  评论(0编辑  收藏  举报