CF368B.Sereja and Suffixes

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Sereja has an array a, consisting of n integers _a_1, _a_2, ..., a__n. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers _l_1, _l_2, ..., l__m (1 ≤ l__i ≤ n). For each number l__i he wants to know how many distinct numbers are staying on the positions l__i, l__i + 1, ..., n. Formally, he want to find the number of distinct numbers among a__l__i, a__l__i + 1, ..., a__n.?

Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each l__i.

Sereja 有一个由 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n 组成的数组 aa。这个男孩坐不住、闲不下来,于是决定研究这个数组。Sereja 拿出一张纸,写下了 mm 个整数 l1, l2, …, lml_1,\ l_2,\ \dots,\ l_m(其中 1≤li≤n1 \leq l_i \leq n)。对于每个数 lil_i,他想知道位置 li, li+1, …, nl_i,\ l_i+1,\ \dots,\ n 上共有多少个互不相同的数。形式上,他希望求出 ali, ali+1, …, ana_{l_i},\ a_{l_i+1},\ \dots,\ a_n 中不同数字的个数。

Sereja 已经写出了所需的数组元素,但该数组规模太大,而男孩时间又非常紧迫。请帮助他,对每个 lil_i 回答上述问题。

输入格式

The first line contains two integers n and m (1 ≤ n, m ≤ 105). The second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 105) — the array elements.

Next m lines contain integers _l_1, _l_2, ..., l__m. The i-th line contains integer l__i (1 ≤ l__i ≤ n).

第一行包含两个整数 nn 和 mm(1 ≤ n, m ≤ 1051 \leq n, m \leq 10^5)。第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1 ≤ ai ≤ 1051 \leq a_i \leq 10^5)—— 数组元素。

接下来 mm 行,每行一个整数 l1, l2, …, lml_1, l_2, \dots, l_m。第 ii 行包含整数 lil_i(1 ≤ li ≤ n1 \leq l_i \leq n)。

输出格式

Print m lines — on the i-th line print the answer to the number l__i.

输出 m 行——在第 i 行输出数字 l__i 对应的答案。

输入输出样例

  • 输入#1

    10 10
    1 2 3 4 1 2 3 4 100000 99999
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    输出#1

    6
    6
    6
    6
    6
    5
    4
    3
    2
    1

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

首页