过了,但是求正确性
查看原帖
过了,但是求正确性
681229
Your_Name楼主2024/12/27 17:08

直接用差分区间加,然后看每个弦前后有没有孤点即可。

但为什么题解都写的那么复杂 QAQ?

代码如下:

#include<bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
int n, a[N], b[N], cnt[N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i ++){
		cin >> a[i] >> b[i];
        if(a[i] > b[i])swap(a[i], b[i]);
		cnt[a[i]] ++;
		cnt[b[i]] --;
	}
	for(int i = 1; i < N; i ++){
		cnt[i] += cnt[i - 1];
	}
	for(int i = 1; i <= n; i ++){
		if(cnt[b[i] - 1] - cnt[a[i]] && cnt[a[i] - 1] + cnt[N - 1] - cnt[b[i]]){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}
2024/12/27 17:08
加载中...