You can take the DSU structure used by me in the following link Problem Solution, also you can try to solve the problem and see how I simply called DSU dsu(n) of size n and
to unite I used dsu.unite(a , b) , to find the parent use dsu.find(a) , to find the size of a component use dsu.siz(a).
Link for example code DSU
Segment Tree
There are two codes for segment tree one is written by tourist and other is standard code.
Link for the standard code Standard Segtree
Link for tourist segtree Segtree