C# program:
using System ; class GFG { public static int MAX = 1000 ; static bool isEvenParity ( int x ) { int parity = 0 ; while ( x != 0 ) { if ( ( x & 1 ) != 0 ) parity ++ ; x = x >> 1 ; } if ( parity % 2 == 0 ) return true ; else return false ; } static int getMid ( int s , int e ) { return s + ( e - s ) / 2 ; } static int queryEvenParityUtil ( int [ ] segmentTree , int segmentStart , int segmentEnd , int queryStart , int queryEnd , int index ) { if ( queryStart <= segmentStart && queryEnd >= segmentEnd ) return segmentTree [ index ] ; if ( segmentEnd < queryStart segmentStart > queryEnd ) return 0 ; int mid = getMid ( segmentStart , segmentEnd ) ; return queryEvenParityUtil ( segmentTree , segmentStart , mid , queryStart , queryEnd , 2 * index + 1 ) + queryEvenParityUtil ( segmentTree , mid + 1 , segmentEnd , queryStart , queryEnd , 2 * index + 2 ) ; } static void updateValueUtil ( int [ ] segmentTree , int segmentStart , int segmentEnd , int i , int diff , int si ) { if ( i < segmentStart i > segmentEnd ) return ; segmentTree [ si ] = segmentTree [ si ] + diff ; if ( segmentEnd != segmentStart ) { int mid = getMid ( segmentStart , segmentEnd ) ; updateValueUtil ( segmentTree , segmentStart , mid , i , diff , 2 * si + 1 ) ; updateValueUtil ( segmentTree , mid + 1 , segmentEnd , i , diff , 2 * si + 2 ) ; } } static void updateValue ( int [ ] arr , int [ ] segmentTree , int n , int i , int new_val ) { if ( i < 0 i > n - 1 ) { Console . WriteLine ( " Invalid ▁ Input " ) ; return ; } int diff = 0 , oldValue = 0 ; oldValue = arr [ i ] ; arr [ i ] = new_val ; if ( isEvenParity ( oldValue ) && isEvenParity ( new_val ) ) return ; if ( ! isEvenParity ( oldValue ) && ! isEvenParity ( new_val ) ) return ; if ( isEvenParity ( oldValue ) && ! isEvenParity ( new_val ) ) { diff = - 1 ; } if ( ! isEvenParity ( oldValue ) && ! isEvenParity ( new_val ) ) { diff = 1 ; } updateValueUtil ( segmentTree , 0 , n - 1 , i , diff , 0 ) ; } static void queryEvenParity ( int [ ] segmentTree , int n , int queryStart , int queryEnd ) { int EvenParityInRange = queryEvenParityUtil ( segmentTree , 0 , n - 1 , queryStart , queryEnd , 0 ) ; Console . WriteLine ( EvenParityInRange ) ; } static int constructSTUtil ( int [ ] arr , int segmentStart , int segmentEnd , int [ ] segmentTree , int si ) { if ( segmentStart == segmentEnd ) { if ( isEvenParity ( arr [ segmentStart ] ) ) segmentTree [ si ] = 1 ; else segmentTree [ si ] = 0 ; return segmentTree [ si ] ; } int mid = getMid ( segmentStart , segmentEnd ) ; segmentTree [ si ] = constructSTUtil ( arr , segmentStart , mid , segmentTree , si * 2 + 1 ) + constructSTUtil ( arr , mid + 1 , segmentEnd , segmentTree , si * 2 + 2 ) ; return segmentTree [ si ] ; } static int [ ] constructST ( int [ ] arr , int n ) { int x = ( int ) ( Math . Ceiling ( Math . Log ( n , 2 ) ) ) ; int max_size = 2 * ( int ) Math . Pow ( 2 , x ) - 1 ; int [ ] segmentTree = new int [ max_size ] ; constructSTUtil ( arr , 0 , n - 1 , segmentTree , 0 ) ; return segmentTree ; } public static void Main ( ) { int [ ] arr = { 18 , 15 , 8 , 9 , 14 , 5 } ; int n = arr . Length ; int [ ] segmentTree = constructST ( arr , n ) ; int start = 0 ; int end = 4 ; queryEvenParity ( segmentTree , n , start , end ) ; int i = 3 ; int x = 11 ; updateValue ( arr , segmentTree , n , i , x ) ; start = 0 ; end = 4 ; queryEvenParity ( segmentTree , n , start , end ) ; } }

Index/key variables: i, index, max_size, segmentStart, si
Accumulator variables: parity
Class/struct names: GFG