-
Notifications
You must be signed in to change notification settings - Fork 2
/
XXOR.c
45 lines (44 loc) · 921 Bytes
/
XXOR.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
int ison(long int x,long int y)
{
if((x&y))
return 1;
else
return 0;
}
int main()
{
long int n,q,i,j;
scanf("%ld%ld",&n,&q);
long int v[n];
for (long int i = 0; i < n; ++i)
scanf("%ld",&v[i]);
long int arr[n+2][32];
for(i=0;i<32;i++)
arr[0][i]=0;
for(i=0;i<31;i++)
{
long int temp=1<<i;
for(j=1;j<=n;j++)
arr[j][i]=arr[j-1][i]+ison(v[j-1],temp);
}
for(i=0;i<q;i++)
{
long int ans=0;
long int l,r;
scanf("%ld%ld",&l,&r);
long int diff=(r-l+1)/2;
if((r-l+1)%2==0)
diff-=1;
long int mul=1;
for(j=0;j<31;j++)
{
// cout<<arr[r][j]-arr[l-1][j]<<endl;
if(arr[r][j]-arr[l-1][j]<=diff)
ans+=mul;
mul*=2;
}
printf("%ld\n",ans);
}
return 0;
}