题目链接:传送门
离散化一下维护一个最值
啊学数据结构学傻了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define
using namespace std;
typedef long long ll;
struct node {int x, y;}e[A];
int n, t[A], cnt, mx;
struct T{int l, r, w, f;}tree[A];
void build(int k, int l, int r) {
tree[k].l = l; tree[k].r = r;
if (l == r) return;
int m = (l + r) >> 1;
build(k << 1, l, m); build(k << 1 | 1, m + 1, r);
}
void down(int k) {
tree[k << 1].f += tree[k].f; tree[k << 1 | 1].f += tree[k].f;
tree[k << 1].w += tree[k].f; tree[k << 1 | 1].w += tree[k].f;
tree[k].f = 0;
}
void add(int k, int l, int r) {
if (tree[k].l >= l and tree[k].r <= r) {
tree[k].w++;
tree[k].f++; return;
}
if (tree[k].f) down(k);
int m = (tree[k].l + tree[k].r) >> 1;
if (l <= m) add(k << 1, l, r);
if (r > m) add(k << 1 | 1, l, r);
tree[k].w = max(tree[k << 1].w, tree[k << 1 | 1].w);
}
int main(int argc, char const *argv[]) {
cin >> n;
for (int i = 1; i <= n; i++) cin >> e[i].x >> e[i].y, t[++cnt] = e[i].x, t[++cnt] = e[i].y;
sort(t + 1, t + cnt + 1); int m = unique(t + 1, t + cnt + 1) - t - 1;
for (int i = 1; i <= n; i++) e[i].x = lower_bound(t + 1, t + m + 1, e[i].x) - t, e[i].y = lower_bound(t + 1, t + m + 1, e[i].y) - t, mx = max(mx, max(e[i].x, e[i].y));
build(1, 1, mx);
for (int i = 1; i <= n; i++) add(1, e[i].x, e[i].y);
cout << tree[1].w << endl;
}