OR of ANDs - Help required

Here Link to question .

#include <bits/stdc++.h>
#define  Boost ios_base :: sync_with_stdio (0) ; cin.tie(0) ; cout.tie(0) ;
#define  int  long long
using namespace std ;

void Go () {
    int n = 0 , q = 0 ;
    cin >> n >> q ; 
    int a[n+1] ;
    int bit[32] ;
    memset(bit,0,sizeof(bit)) ;
    int Or = 0 ;
    for ( int i = 1 ; i <= n ; i++ ) {
        int x = 0 ;
        cin >> x ;
        a[i] = x ;
        Or |= x ;
        int j = 0 ;
        while ( x ) {
            if ( (x&1) > 0 ) {
                bit[j]++ ;
            }
            j++ ;
            x >>= 1 ;
        }
    }

    cout << Or << endl ;
    while ( q-- ) {
        int ps = 0 , val = 0 ;
        cin >> ps >> val ;
        int x = a[ps] ;
        int j = 0 ;
        while ( x > 0 ) {
            if ((x&1) > 0) {
                bit[j]-- ;
            }
            x >>= 1 ;
            j++ ;
        }
        j = 0 ;
        while ( val > 0 ) {
            if ((val&1) > 0 ) {
                bit[j]++ ;
            }
            val >>= 1 ;
            j++ ;
        }
        Or = 0 ;
        for ( int i = 0 ; i < 32 ; i++ ) {
            if ( bit[i] > 0 ) {
                Or += (1<<i) ;
            }
        }
        cout << Or << endl ;
    }   
}

int32_t main () {
    Boost 
    int t = 1 ;
    cin >> t ;
    while ( t-- ) {
        Go() ;
    }
    return 0 ;
}

Here is link to solution
https://www.codechef.com/viewsolution/45286501

Plz tell why it is giving me wrong ans

Try this test-case

TEST_CASE
1
1 5
6
1 1
1 6
1 1
1 9
1 7
CORRECT_OUTPUT
6
1
6
1
9
7

YOUR_OUTPUT
6
1
1
1
9
9

2 Likes

Thx Bro I got the mistake by using your testcase .
One line i want to say is that your contribution to this community is really awsome.
Hats off to you bro .

1 Like