updown

Untitled

Jun 13th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. int query(int node, int p, int height) {
  2. //how to make sure doesn't TLE? if we have to check every range??
  3. if (node <= 0)
  4. return 0;
  5.  
  6. int cnt = 0;
  7. for (eqpair p : seg[node]) {
  8. if (deleted.find(p) == deleted.end() && p.h <= height) {
  9. cnt++;
  10. deleted.insert(p);
  11. }
  12.  
  13. // todo: make sure the set is sorted by height
  14.  
  15. if (p.h > height)
  16. break;
  17. }
  18.  
  19. set<eqpair>::iterator it;
  20. while (seg[node].size() > 0) {
  21. it = seg[node].begin();
  22. if ((*it).h <= height) {
  23. seg[node].erase(it);
  24. }
  25. else
  26. break;
  27.  
  28. }
  29.  
  30.  
  31.  
  32. return cnt + query(node/2, p, height);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment