离散化
AC代码:
struct node
{
ll s, e;
} p[100010];
ll ls[200010], ct = 1;
ll ans[200010];
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
ct = 1;
fill(ans, ans + 200001, 0);
for (int i = 1; i <= n; i++)
{
cin >> p[i].s >> p[i].e;
ls[ct++] = p[i].s;
ls[ct++] = p[i].e;
}
sort(ls + 1, ls + 1 + n * 2);
int len = unique(ls + 1, ls + 1 + 2 * n) - ls;
for (int i = 1; i <= n; i++)
{
ll temp1 = lower_bound(ls + 1, ls + 1 + len, p[i].s) - ls;
ll temp2 = lower_bound(ls + 1, ls + 1 + len, p[i].e) - ls;
ans[temp1]++;
ans[temp2]--;
}
ll anss = 0;
for (int i = 1; i <= len; i++)
ans[i] += ans[i - 1], anss = max(anss, ans[i]);
cout << len - 1 << ' ' << anss << endl;
}
return 0;
}
另外两题明天再补