import
java.io.*;
import
java.util.*;
class
Query
{
int
L, R, K, index;
int
odd;
int
even;
Query(
int
L,
int
R,
int
K,
int
index,
int
odd,
int
even)
{
this
.L = L;
this
.R = R;
this
.K = K;
this
.index = index;
this
.odd = odd;
this
.even = even;
}
}
class
GFG{
static
int
block;
static
int
count_oddP;
static
void
add(
int
currL,
int
a[])
{
if
(__builtin_parity(a[currL]))
count_oddP++;
}
static
void
remove(
int
currR,
int
a[])
{
if
(__builtin_parity(a[currR]))
count_oddP--;
}
static
void
queryResults(
int
a[],
int
n, Query q[],
int
m)
{
count_oddP =
0
;
block = (
int
)(Math.sqrt(n));
Arrays.sort(q, (Query x, Query y) ->
{
if
(x.L / block != y.L / block)
return
x.L / block - y.L / block;
return
x.R - y.R;
});
int
currL =
0
, currR =
0
;
for
(
int
i =
0
; i < m; i++)
{
int
L = q[i].L, R = q[i].R, k = q[i].K;
while
(currR <= R)
{
add(currR, a);
currR++;
}
while
(currL > L)
{
add(currL -
1
, a);
currL--;
}
while
(currR > R +
1
)
{
remove(currR -
1
, a);
currR--;
}
while
(currL < L)
{
remove(currL, a);
currL++;
}
if
(!__builtin_parity(k))
{
q[i].odd = count_oddP;
q[i].even = R - L +
1
- count_oddP;
}
else
{
q[i].odd = R - L +
1
- count_oddP;
q[i].even = count_oddP;
}
}
}
static
boolean
__builtin_parity(
int
K)
{
return
(Integer.bitCount(K) %
2
) ==
1
;
}
static
void
printResults(Query q[],
int
m)
{
Arrays.sort(q, (Query x, Query y) ->
x.index - y.index);
for
(
int
i =
0
; i < m; i++)
{
System.out.println(q[i].odd +
" "
+
q[i].even);
}
}
public
static
void
main(String[] args)
{
int
arr[] = {
5
,
2
,
3
,
1
,
4
,
8
,
10
};
int
n = arr.length;
Query q[] =
new
Query[
3
];
q[
0
] =
new
Query(
0
,
5
,
3
,
0
,
0
,
0
);
q[
1
] =
new
Query(
1
,
4
,
8
,
1
,
0
,
0
);
q[
2
] =
new
Query(
4
,
6
,
10
,
2
,
0
,
0
);
int
m = q.length;
queryResults(arr, n, q, m);
printResults(q, m);
}
}