Problem link — 1354D - Мультимножество
Solution link — 143561353
I am using segment tree. The time complexity of the code is O( n * ( (logN)^2 ) ) which should pass the time limit. I am also using ios_base::sync_with_stdio(0);cin.tie(0);
for fast IO.