Codeforces Round 204 (Div. 1)
D
Jeff and Removing Periods
Codeforces
2700
原题
← CE →
翻译中…

Cosider a sequence, consisting of $*n*$ integers: $*a*_{1}$, $*a*_{2}$, $...$, $*a*_{*n*}$. Jeff can perform the following operation on sequence $*a*$:

翻译中…
  • take three integers $*v*$, $*t*$, $*k*$ $(1 ≤ *v*, *t* ≤ *n*; 0 ≤ *k*; *v* + *tk* ≤ *n*)$, such that $*a*_{*v*}$ = $*a*_{*v* + *t*}$, $*a*_{*v* + *t*}$ = $*a*_{*v* + 2*t*}$, $...$, $*a*_{*v* + *t*(*k* - 1)}$ = $*a*_{*v* + *tk*}$;
  • remove elements $*a*_{*v*}$, $*a*_{*v* + *t*}$, $...$, $*a*_{*v* + *t*·*k*}$ from the sequence $*a*$, the remaining elements should be reindexed $*a*_{1}, *a*_{2}, ..., *a*_{*n* - *k* - 1}$.
  • permute in some order the remaining elements of sequence $*a*$.
翻译中…

A beauty of a sequence $*a*$ is the minimum number of operations that is needed to delete all elements from sequence $*a*$.

翻译中…

Jeff's written down a sequence of $*m*$ integers $*b*_{1}$, $*b*_{2}$, $...$, $*b*_{*m*}$. Now he wants to ask $*q*$ questions. Each question can be described with two integers $*l*_{*i*}, *r*_{*i*}$. The answer to the question is the beauty of sequence $*b*_{*l*_{*i*}}$, $*b*_{*l*_{*i*} + 1}$, $...$, $*b*_{*r*_{*i*}}$. You are given the sequence $*b*$ and all questions. Help Jeff, answer all his questions.

翻译中…

Input

翻译中…

The first line contains integer $*m*$ $(1 ≤ *m* ≤ 10^{5})$. The next line contains $*m*$ integers $*b*_{1}$, $*b*_{2}$, $...$, $*b*_{*m*}$ $(1 ≤ *b*_{*i*} ≤ 10^{5})$.

翻译中…

The third line contains integer $*q*$ $(1 ≤ *q* ≤ 10^{5})$ — the number of questions. The next $*q*$ lines contain pairs of integers, $*i*$-th of them contains a pair of integers $*l*_{*i*}$, $*r*_{*i*}$ $(1 ≤ *l*_{*i*} ≤ *r*_{*i*} ≤ *m*)$ — the description of $*i*$-th question.

翻译中…

Output

翻译中…

In $*q*$ lines print the answers to Jeff's queries. Print the answers according to the order of questions in input.

翻译中…

样例

Input #1
5
2 2 1 1 2
5
1 5
1 1
2 2
1 3
2 3
Output #1
2
1
1
2
2
InputCopy OutputCopy
Input #2
10
2 1 3 3 3 3 1 3 1 1
10
4 8
2 10
1 10
4 4
1 3
2 4
6 7
1 9
2 5
1 1
Output #2
2
3
3
1
3
2
2
3
2
1
InputCopy OutputCopy
题目信息
题号
351D
时间限制
3 s
内存限制
256 MB
标签
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。