Codeforces845C

来源:互联网 发布:书法集字软件 编辑:程序博客网 时间:2024/05/28 03:03

扫描线的简单运用。

#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int, int> P;const int N = 2E5 + 7;vector<P> a;int n;int main(){    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);    cin >> n;    for(int i = 1;i <= n;i ++)    {        int l, r;        cin >> l >> r;        a.push_back(make_pair(l, 1));        a.push_back(make_pair(r + 1, -1));    }    sort(begin(a), end(a));    int cnt = 0;    for(auto it : a) {        cnt += it.second;        if(cnt > 2) {            cout << "NO" << endl ; return 0;        }    }    cout << "YES" << endl;    return 0;}


原创粉丝点击