shinzanmono @ 2023-01-04 21:14:44
#include<iostream>
#include<algorithm>
#include<set>
const int sz = 1e3 + 10;
int arr[sz << 1], xpp, res[sz << 1];
std::pair<int, int> modify[sz];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
for (int i = 1, a, b; i <= m; i++)
std::cin >> a >> b, modify[i] = std::make_pair(a, b), arr[++xpp] = a, arr[++xpp] = b;
std::sort(arr + 1, arr + xpp + 1);
int f = std::unique(arr + 1, arr + xpp + 1) - arr;
for (int i = 1; i <= m; i++)
modify[i] = std::make_pair(std::lower_bound(arr + 1, arr + f, modify[i].first) - arr,
std::lower_bound(arr + 1, arr + f, modify[i].second) - arr);
for (int i = 1; i <= m; i++)
for (int j = modify[i].first; j <= modify[i].second; j++) res[j] = i;
std::set<int> ans;
for (int i = 1; i < f; i++)
ans.insert(res[i]);
std::cout << ans.size();
return 0;
}
by linyihdfj @ 2023-01-04 21:34:10
例如某篇讨论提供的 hack:
114514 3
1 10
1 4
7 10
估计就能懂了吧,答案是 3
by dbg_8 @ 2023-01-05 22:29:30
114514 3
1 5
1 2
4 5
这个也试试 答案是 3
by Miss_SGT @ 2023-05-03 00:00:52
@linyihdfj 很好,这两个hack都改过了,60变50