You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int b[2 * N]; // key,value:第几个端点,坐标值
int idx; // 用于维护数组b的游标
int n; // 共几个区间
int res = 1; // 全放到一个组中最小默认值1
int main() {
cin >> n; // n个区间
for (int i = 1; i <= n; i++) {
int l, r;
cin >> l >> r;
b[idx++] = l * 2; // 标记左端点为偶数;同比放大2倍还不影响排序的位置牛~
b[idx++] = r * 2 + 1; // 标记右端点为奇数;同比放大2倍还不影响排序的位置牛~
}
// 将所有端点放在一起排序,由小到大
sort(b, b + idx);
int t = 0;
for (int i = 0; i < idx; i++) {
if (b[i] % 2 == 0)
t++; // 左端点+1
else
t--; // 右端点-1
res = max(res, t); // 动态计算什么时间点时,出现左的个数减去右的个数差最大,就是冲突最多的时刻
}
// 输出结果
cout << res << endl;
return 0;
}