C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  1000
bool isEvenParity ( int x ) { int parity = 0 ; while ( x != 0 ) { if ( x & 1 ) parity ++ ; x = x >> 1 ; } if ( parity % 2 == 0 ) return true ; else return false ; } int getMid ( int s , int e ) { return s + ( e - s ) / 2 ; } 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 ) ; } 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 ) ; } } void updateValue ( int arr [ ] , int * segmentTree , int n , int i , int new_val ) { if ( i < 0 i > n - 1 ) { printf ( " Invalid ▁ Input " ) ; return ; } int diff , oldValue ; 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 ) ; } void queryEvenParity ( int * segmentTree , int n , int queryStart , int queryEnd ) { int EvenParityInRange = queryEvenParityUtil ( segmentTree , 0 , n - 1 , queryStart , queryEnd , 0 ) ; cout << EvenParityInRange << " STRNEWLINE " ; } 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 ] ; } int * constructST ( int arr [ ] , int n ) { int x = ( int ) ( ceil ( log2 ( n ) ) ) ; int max_size = 2 * ( int ) pow ( 2 , x ) - 1 ; int * segmentTree = new int [ max_size ] ; constructSTUtil ( arr , 0 , n - 1 , segmentTree , 0 ) ; return segmentTree ; } int main ( ) { int arr [ ] = { 18 , 15 , 8 , 9 , 14 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; 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 ) ; return 0 ; }

Index/key variables: i, index, max_size, segmentStart, si
Accumulator variables: parity, stdc