Getting WA in TYTACTIC

I have been trying out this question and was getting WA. Initially, i thought my segment tree was wrong so i took it from gfg to test. Also the code is showing undefined behavior if i convert all int to ll(long long). But for second subtask we have to take long long ,Right?
Can someone please help me with the test cases where it fails. I would be really thankful.

Question link :- https://www.codechef.com/problems/TYTACTIC
My Code :- https://www.codechef.com/viewsolution/16151710

Thanks in advance.

@vijju123 can you please have a look at it. I did the same what others did, use of segment tree and euler tour to get continuous range sum but could not get the answer. Please Help!!