using
System;
using
System.Collections.Generic;
class
Program
{
static
List<
int
> MinQuery(
int
N,
int
Q, List<
int
> A, List<List<
int
>> Queries)
{
List<List<
int
>> v =
new
List<List<
int
>>(N + 1);
for
(
int
i = 0; i <= N; i++)
{
v.Add(
new
List<
int
>(
new
int
[31]));
}
for
(
int
i = 1; i <= N; i++)
{
for
(
int
j = 0; j < 31; j++)
{
v[i][j] = v[i - 1][j] + ((A[i - 1] >> j) & 1);
}
}
List<
int
> ans =
new
List<
int
>(Q);
for
(
int
i = 0; i < Q; i++)
{
int
a1 = 0;
int
a2 = 0;
int
l1 = Queries[i][0], r1 = Queries[i][1],
l2 = Queries[i][2], r2 = Queries[i][3];
for
(
int
j = 0; j < 31; j++)
{
if
(v[r1][j] - v[l1 - 1][j] == (r1 - l1 + 1))
a1 += (1 << j);
if
(v[r2][j] - v[l2 - 1][j] == (r2 - l2 + 1))
a2 += (1 << j);
}
ans.Add(a1 | a2);
}
return
ans;
}
static
void
Main()
{
int
N = 5;
int
Q = 2;
List<
int
> A =
new
List<
int
> { 2, 3, 7, 11, 15 };
List<List<
int
>> Queries =
new
List<List<
int
>>
{
new
List<
int
> { 2, 4, 3, 5 },
new
List<
int
> { 1, 5, 2, 3 }
};
List<
int
> result = MinQuery(N, Q, A, Queries);
foreach
(
var
a
in
result)
{
Console.Write($
"{a} "
);
}
}
}