import
java.util.*;
public
class
Main {
static
class
Query {
int
l, r, id;
Query(
int
l,
int
r,
int
id) {
this
.l = l;
this
.r = r;
this
.id = id;
}
}
static
int
n, q, block_size;
static
int
[] a, ans, cnt;
static
class
QueryComparator
implements
Comparator<Query> {
@Override
public
int
compare(Query a, Query b) {
if
(a.l / block_size != b.l / block_size) {
return
Integer.compare(a.l, b.l);
}
return
((a.l / block_size) &
1
) ==
0
? Integer.compare(a.r, b.r) : Integer.compare(b.r, a.r);
}
}
static
void
add(
int
x) {
cnt[a[x]]++;
if
(cnt[a[x]] ==
1
) {
ans[
0
]++;
}
}
static
void
remove(
int
x) {
cnt[a[x]]--;
if
(cnt[a[x]] ==
0
) {
ans[
0
]--;
}
}
public
static
void
main(String[] args) {
n =
12
;
q =
3
;
block_size = (
int
) Math.sqrt(n);
int
[] array = {
1
,
2
,
2
,
2
,
3
,
4
,
5
,
5
,
5
,
6
,
6
,
6
};
a =
new
int
[n +
1
];
for
(
int
i =
0
; i < n; i++) {
a[i +
1
] = array[i];
}
int
l1 =
1
, r1 =
4
, l2 =
2
, r2 =
6
, l3 =
3
, r3 =
8
;
Query[] qry =
new
Query[q];
qry[
0
] =
new
Query(l1, r1,
0
);
qry[
1
] =
new
Query(l2, r2,
1
);
qry[
2
] =
new
Query(l3, r3,
2
);
Arrays.sort(qry,
new
QueryComparator());
int
l =
1
, r =
0
;
cnt =
new
int
[n];
ans =
new
int
[q +
1
];
for
(
int
i =
0
; i < q; i++) {
while
(l > qry[i].l)
add(--l);
while
(r < qry[i].r)
add(++r);
while
(l < qry[i].l)
remove(l++);
while
(r > qry[i].r)
remove(r--);
ans[qry[i].id] = ans[
0
];
}
for
(
int
i =
0
; i < q; i++)
System.out.println(ans[i]);
}
}