Don't know why my solution is not getting accepted for the question OROFAND

I don’t know why my code is not getting accepted even though it is completely correct for the question with code OROFAND in today’s cookoff.
https://www.codechef.com/viewsolution/45214117

1<<32 is int overflow.

defined int as long long in the beginning

wont help here tho… 1 is still int32_t. Change it to 1LL.
edit: nvm.

#include<bits/stdc++.h>
#define ll long long
#define vi vector
#define mod 998244353
#define inf 1e18
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;

/*int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};

ll pow(ll x, ll y, ll p) {
ll res = 1;
x = x % p;

if(x == 0) 
    return 0;

while(y > 0) {
    if(y & 1)
        res = (res * x) % p;

    y = y >> 1;
    x = (x * x) % p;
}

return res;

}

ll _pow(ll a, ll b) {
if(!b)
return 1;

ll temp = _pow(a, b / 2);
temp = temp * temp;

if(b & 1)
    return a * temp;
return temp;

}

ll C[2001][2001];

ll calncr(int a, int b)
{
for(int n = 0 ; n <= a ; ++n){
for(int r = 0 ; r <= n ;++r){
if(n==r){
C[n][r] = 1;
}
else if(r == 0){
C[n][r] = 1 ;
}
else if(r == 1){
C[n][r] = n;
}
else{
C[n][r] = (C[n-1][r]%1000000007 + C[n-1][r-1]%1000000007)%1000000007 ;
}

     }
 }
 //cout<<C[4][2];
 return C[a][b];

}
*/

void solve(){
int n,q;
cin>>n>>q;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int hel[32]={0};
//int temp=1;
for(int i=0;i<n;i++){
for(int j=0;j<32;j++){
if(arr[i]&(1<<j))
hel[j]++;
//cout<<hel[0]<<" “<<hel[1]<<endl;
}
}
int ans=0;
for(int i=0;i<32;i++){
//cout<<hel[i]<<” ";
if(hel[i])
ans+=pow(2,i);
}
cout<<ans<<’\n’;

//cout<<score(arr,n)<<'\n';
while(q>0){
    int x,v;
    cin>>x>>v;
    x=arr[x-1];
    for(int j=0;j<32;j++){
        if(x&(1<<j))
        hel[j]--;
      }
      //cout<<hel[0]<<" "<<hel[1]<<" "<<hel[2]<<endl;
    for(int j=0;j<32;j++){
        if(v&(1<<j))
        hel[j]++;
      }
      //cout<<hel[0]<<" "<<hel[1]<<" "<<hel[2]<<endl;
      ans=0;

      for(int i=0;i<32;i++){
          if(hel[i])
          ans+=pow(2,i);
        }
    cout<<ans<<'\n';
    q--;
}

}

int32_t main() {

//clock_t start = clock();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
//int i=0;
while(t–){
//i++;
//cout<<“Case #”<<i<<": ";
solve();
}
/clock_t end = clock();
double elapsed = double(end - start)/CLOCKS_PER_SEC;
printf(“Time measured: %.3f seconds.\n”, elapsed);
/
return 0;
}

Even this is not working

Try this test case:
1
3 5
1 2 3
1 4
3 0
1 5
1 1
1 214783640

Your Output:
3
7
6
6
6
214783647

Correct Output:
3
7
6
7
3
214783642

If you can find the error on your own with this case, then that’s great, otherwise let me know, I will tell you the error.

And integer overflow is not an issue with the given code, I think. So, try something else.

1 Like

You forget to change the current value of array after each query , I have made some changes here is your accepted solution

1 Like

thanks a lot

Yeah, did the same mistake and got 1 penalty :grimacing: