Function to solve all the queries
void solve ( int n , int q , vector < int > & arr , vector < vector < int > > & query ) { vector < int > seg_tree ( 4 * n + 1 , 0 ) ; build_tree ( arr , seg_tree , 1 , 0 , n - 1 ) ; for ( int i = 1 ; i <= q ; i ++ ) {