首页 > 其他分享 >离散化

离散化

时间:2022-11-15 14:55:08浏览次数:41  
标签:int back segs 离散 ++ dis

  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));
 

标签:int,back,segs,离散,++,dis
From: https://www.cnblogs.com/er007/p/16892413.html

相关文章