ruhan008

segTree

Sep 29th, 2025
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. {
  2. "": {
  3. "prefix": "cd_seg",
  4. "body": [
  5. "class segTree {",
  6. "private:",
  7. " vector<int> arr;",
  8. " int size;",
  9. "public:",
  10. " segTree(int n) {",
  11. " size = 1;",
  12. " while(size < n) size *= 2;",
  13. " arr.resize(2 * size, 0);",
  14. " }",
  15. "",
  16. " void propagate(int x, int lx, int rx) {",
  17. " if(lx == rx) return ;",
  18. " }",
  19. "",
  20. " void build(int x, int lx, int rx) {",
  21. " if(lx == rx) {",
  22. "",
  23. " return ;",
  24. " }",
  25. "",
  26. " int mid = (lx + rx) / 2;",
  27. " build(2 * x + 1, lx, mid);",
  28. " build(2 * x + 2, mid + 1, rx);",
  29. " }",
  30. "",
  31. " void build() {",
  32. " build(0, 0, size - 1);",
  33. " }",
  34. "",
  35. " void set(int x, int lx, int rx) {",
  36. "",
  37. " int mid = (lx + rx) / 2;",
  38. " set(2 * x + 1, lx, mid);",
  39. " set(2 * x + 2, mid + 1, rx);",
  40. " }",
  41. "",
  42. " void set() {",
  43. " set(0, 0, size - 1);",
  44. " }",
  45. "",
  46. " int getValue(int x, int lx, int rx) {",
  47. " int mid = (lx + rx) / 2;",
  48. " getValue(2 * x + 1, lx, mid);",
  49. " getValue(2 * x + 2, mid + 1, rx);",
  50. " }",
  51. "",
  52. " int getValue() {",
  53. " return getValue(0, 0, size - 1);",
  54. " }",
  55. "};",
  56. ""
  57. ],
  58. "description": ""
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment