CF351D.Jeff and Removing Periods

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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.

考虑一个由 nn 个整数组成的序列:a1,a2,…,ana_1, a_2, \dots, a_n。Jeff 可以对序列 aa 执行如下操作:

  • 选取三个整数 vv、tt、kk(满足 1≤v,t≤n1 \le v, t \le n;0≤k0 \le k;且 v+tk≤nv + tk \le n),使得
    av=av+t,  av+t=av+2t,  …,  av+t(k−1)=av+tka_v = a_{v+t},\; a_{v+t} = a_{v+2t},\; \dots,\; a_{v+t(k-1)} = a_{v+tk};
  • 从序列 aa 中删除元素 av,av+t,…,av+tka_v, a_{v+t}, \dots, a_{v+tk},剩余元素需重新编号为 a1,a2,…,an−k−1a_1, a_2, \dots, a_{n-k-1};
  • 将序列 aa 中剩余的元素以任意顺序重新排列。

序列 aa 的**优美值(beauty)**定义为:将序列 aa 中所有元素全部删除所需的最少操作次数。

Jeff 已写下长度为 mm 的整数序列 b1,b2,…,bmb_1, b_2, \dots, b_m。现在他要提出 qq 个询问,每个询问由两个整数 li,ril_i, r_i 描述。该询问的答案即为子序列 bli,bli+1,…,brib_{l_i}, b_{l_i+1}, \dots, b_{r_i} 的优美值。
已知序列 bb 及所有询问,请帮助 Jeff 回答全部询问。

输入格式

The first line contains integer m (1 ≤ m ≤ 105). The next line contains m integers _b_1, _b_2, ..., b__m (1 ≤ b__i ≤ 105).

The third line contains integer q (1 ≤ q ≤ 105) — 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.

第一行包含一个整数 mm(1≤m≤1051 \leq m \leq 10^5)。第二行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \dots, b_m(1≤bi≤1051 \leq b_i \leq 10^5)。

第三行包含一个整数 qq(1≤q≤1051 \leq q \leq 10^5)—— 问题的数量。接下来的 qq 行每行包含一对整数,其中第 ii 行包含一对整数 li,ril_i, r_i(1≤li≤ri≤m1 \leq l_i \leq r_i \leq m)—— 描述第 ii 个问题。

输出格式

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

在 q 行中输出 Jeff 的查询结果。请按照输入中问题的顺序输出答案。

输入输出样例

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

输入解题思路,AI测评打分。不知道怎么写?

首页