CF351D.Jeff and Removing Periods

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Cosider a sequence, consisting of nn integers: a1a_{1} , a2a_{2} , ...... , ana_{n} . Jeff can perform the following operation on sequence aa :

  • take three integers vv , tt , kk (1<=v,t<=n; 0<=k; v+tk<=n)(1<=v,t<=n; 0<=k; v+tk<=n) , such that ava_{v} = av+ta_{v+t} , av+ta_{v+t} = av+2ta_{v+2t} , ...... , av+t(k1)a_{v+t(k-1)} = av+tka_{v+tk} ;
  • remove elements ava_{v} , av+ta_{v+t} , ...... , av+tka_{v+t·k} from the sequence aa , the remaining elements should be reindexed a1,a2,...,ank1a_{1},a_{2},...,a_{n-k-1} .
  • permute in some order the remaining elements of sequence aa .

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

Jeff's written down a sequence of mm integers b1b_{1} , b2b_{2} , ...... , bmb_{m} . Now he wants to ask qq questions. Each question can be described with two integers li,ril_{i},r_{i} . The answer to the question is the beauty of sequence blib_{li} , bli+1b_{li}+1 , ...... , brib_{ri} . You are given the sequence bb and all questions. Help Jeff, answer all his questions.

输入格式

The first line contains integer mm (1<=m<=105)(1<=m<=10^{5}) . The next line contains mm integers b1b_{1} , b2b_{2} , ...... , bmb_{m} (1<=bi<=105)(1<=b_{i}<=10^{5}) .

The third line contains integer qq (1<=q<=105)(1<=q<=10^{5}) — the number of questions. The next qq lines contain pairs of integers, ii -th of them contains a pair of integers lil_{i} , rir_{i} (1<=li<=ri<=m)(1<=l_{i}<=r_{i}<=m) — the description of ii -th question.

输出格式

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

输入输出样例

  • 输入#1

    5
    2 2 1 1 2
    5
    1 5
    1 1
    2 2
    1 3
    2 3
    

    输出#1

    2
    1
    1
    2
    2
    
  • 输入#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
    

    输出#2

    2
    3
    3
    1
    3
    2
    2
    3
    2
    1
    
首页