Problem - F - Codeforces
题意:
思路:
这题没什么性质可言,可以说就是纯纯的套路题
既然存在一条线段和其他所有线段相交,不知道是哪条线段,考虑枚举这条线段,然后计数没有交点的线段个数,取min
对于这个计数是个典,考虑将所有线段的端点扔进vec里,二分计算贡献即可
Code:
#include <bits/stdc++.h>
#define int long long
using i64 = long long;
constexpr int N = 2e5 + 10;
constexpr int M = 1e5 + 10;
constexpr int P = 2600;
constexpr i64 Inf = 1e18;
constexpr int mod = 1e9 + 7;
constexpr double eps = 1e-6;
int n;
int l[N], r[N];
void solve() {
std::cin >> n;
std::vector<int> L, R;
for (int i = 1; i <= n; i ++) {
std::cin >> l[i] >> r[i];
L.push_back(l[i]);
R.push_back(r[i]);
}
std::sort(L.begin(), L.end());
std::sort(R.begin(), R.end());
int ans = 1e9;
for (int i = 1; i <= n; i ++) {
int res = 0;
int pos1 = std::upper_bound(L.begin(), L.end(), r[i]) - L.begin() + 1;
res += (n - pos1 + 1);
int pos2 = std::lower_bound(R.begin(), R.end(), l[i]) - R.begin() + 1;
res += pos2 - 1;
ans = std::min(ans, res);
}
std::cout << ans << "\n";
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}