Please help me find error in my code

my code-:

Hey @be10046.19, the issue is in the indexing of the segment tree.
In main function it seems like you’re using 1 based indexing (since you called build(1,1,n) and not build(1,0,n-1)) also in the queries you’re using i and not i-1.
But in build_tree and update_query function you’re calling 2idx,2idx+1, whereas if you’re using 1 based indexing you should rather call 2idx+1,2idx+2. You just have to be consitent with indexing everywhere and you’re good to go.