Find Array obtained after adding terms of AP for Q queries | C # program for the above approach ; Function to find array after performing the given query to the array elements ; Traverse the given query ; Traverse the given array ; Update the value of A [ i ] ; Update the value of curr ; Print the array elements ; Driver code ; Function Call
using System ; class GFG { public static void addAP ( int [ ] A , int Q , int [ , ] operations ) { for ( int j = 0 ; j < 2 ; ++ j ) { int L = operations [ j , 0 ] , R = operations [ j , 1 ] , a = operations [ j , 2 ] , d = operations [ j , 3 ] ; int curr = a ; for ( int i = L - 1 ; i < R ; i ++ ) { A [ i ] += curr ; curr += d ; } } for ( int i = 0 ; i < 4 ; ++ i ) Console . Write ( A [ i ] + " ▁ " ) ; } public static void Main ( string [ ] args ) { int [ ] A = { 5 , 4 , 2 , 8 } ; int Q = 2 ; int [ , ] query = { { 1 , 2 , 1 , 3 } , { 1 , 4 , 4 , 1 } } ; addAP ( A , Q , query ) ; } }