also i am using pass by reference and segment tree method. not able to optimize any further, i think my time complexity is O(nlogn) only, but getting tle, not able to find mistake, please help solution 194602929 solution link : https://mirror.codeforces.com/contest/380/submission/194602929








Maybe you should just change to a different data structure, e.g., a sparse table. The constant factor for SegmentTrees are too big.
Maybe the code is close to avoid TLE so you can try a few minor optimizations. For examples:
A. Change
B. Simplify query() to return int instead of vector.
C. Use int[4*n][3] instead of:
It's IO bottleneck, you can find some codeforces blogs on this topic.
Add
ios_base::sync_with_stdio(false);at the start of your program. And don't use endl if flushing the buffer (needed in interactive problems only) is not needed as its slow; use '\n'.Here is your submission with changes: https://mirror.codeforces.com/contest/380/submission/194658328