I'm trying to solve Div1D on Codeforces Round 250 — The Child and Sequence. My idea is the same with the editorial: Build the maximum and sum segment tree, and for queries of type 2, I keep finding the largest number in the segment, mod it by x until there's no number in the segment larger or equal x. (All is done by segment tree). However, I got TLE on test 4.
My submission: 12348730
I can't find anything wrong with my solution, so that's why I need help on this. Can anyone help me with this? Thanks in advanced.