首先说明我是菜鸡,这是我的O(n)方法做 #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> PLL; const int N = 2e5 + 10; void solve() { int n; cin >> n; int p, f = 1; for (int i = 1; i <= n; i ++ ) { int l, r; cin >> l >> r; if (i == 1) p = r; if (p < l || p > r) f = 0; } if (f) cout << "Yes\n"; else cout << "No\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int _ = 1; cin >> _; while (_ -- ) solve(); return 0; } 思路,从第一个区间到第n - 1个区间任取一个右端点,然后这个点必须在其他区间范围内,就A了。 反之,从第n个区间到第二个区间任取一个左端点,然后这个点必须在其他区间范围内。 两种方法都行
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务