Xor sequence from hackerrank

problem link:
https://www.hackerrank.com/challenges/xor-se/problem

solution :

#include <bits/stdc++.h>
using namespace std ;

long long int ans1[100001] , ans2[100001] ;

int main()
{

int query ; 
cin >> query ; 

ans1[0] = 0 , ans2[0] = 0 ;

for(int i = 1 ; i <= 100000 ; ++i){
    
    ans1[i] = i ^ ans1[i-1] ;
    ans2[i] = ans1[i] ^ ans2[i-1] ;
}
int left , right ;  

while(query --){
    cin >> left >> right ;
    long long int pika = ans2[right] ^ ans2[left - 1] ;
    cout << pika  << "\n";
}
return 0;

}
I am getting segmentation fault for few cases. Can Somebody help me out?
@everule1

1 Like

Please Format your code.
Left and right are up to 10^{15}. So you will get segfault.

1 Like

My bad got it . Thought it was 10 ^ 5.