离散化

  1. V<int> dis; // 离散化数组
  2. V<int> l(n), r(n);
  3. for (int i = 0; i < n; i++) {
  4. cin >> l[i] >> r[i];
  5. dis.push_back(l[i]), dis.push_back(r[i]);
  6. }
  7. // 离散化
  8. sort(all(dis));
  9. dis.erase(unique(all(dis)), dis.end());
  10. for (int i = 0; i < n; i++) {
  11. l[i] = lower_bound(all(dis), l[i]) - dis.begin() + 1;
  12. r[i] = lower_bound(all(dis), r[i]) - dis.begin() + 1;
  13. }
  14.  
  15. V<int,int> segs;
  16. for (int i = 0; i < n; i++) segs.push_back({ l[i],r[i] });
  17. sort(all(segs));
 
posted @ 2022-11-15 14:48  er007  阅读(13)  评论(0编辑  收藏  举报