time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1, l2, ..., lm (1 ≤ li ≤ n). For each number li he wants to know how many distinct numbers are staying on the positions lili + 1, ..., n. Formally, he want to find the number of distinct numbers among ali, ali + 1, ..., an.?

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 li.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the array elements.

Next m lines contain integers l1, l2, ..., lm. The i-th line contains integer li (1 ≤ li ≤ n).

Output

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

Examples
input

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

Copy
6
6
6
6
6
5
4
3
2
1
#include<iostream>
using namespace std;
int n,m,a[],dp[],vis[];
int main()
{
while(cin>>n>>m)
{
for(int i=;i<n;i++)
{
cin>>a[i];
}
dp[n-]=;
for(int i=n-;i>=;i--)
{
if(vis[a[i]]==)
dp[i]=dp[i+]+;
else
dp[i]=dp[i+];
vis[a[i]]=; }
while(m--)
{
int t;
cin>>t;
cout<<dp[t-]<<endl;
}
}
return ;
}

B. Sereja and Suffixes的更多相关文章

  1. Codeforces Round #215 (Div. 2) B. Sereja and Suffixes map

    B. Sereja and Suffixes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  2. Sereja and Suffixes(思维)

    Sereja and Suffixes Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  3. B. Sereja and Suffixes(cf)

    http://codeforces.com/problemset/problem/368/B B. Sereja and Suffixes time limit per test 1 second m ...

  4. Codeforces Round #215 (Div. 2) B. Sereja and Suffixes

    #include <iostream> #include <vector> #include <algorithm> #include <set> us ...

  5. CodeForces 368B Sereja and Suffixes

    题意:给你一个序列,问你从l位置到结尾有多少个不同的数字. 水题,设dp[i]表示从i位置到结尾不同数字的个数,那么dp[i] = dp[i+1] + (vis[a[i]] == 0),在O(n)时间 ...

  6. Sereja and Suffixes

    Codeforces Round #215 (Div. 2) B:http://codeforces.com/problemset/problem/368/B 题意:给你一个序列,然后查询i--n中没 ...

  7. cf B. Sereja and Suffixes

    http://codeforces.com/contest/368/problem/B 从后往前找一遍就可以. #include <cstdio> #include <cstring ...

  8. CF380C. Sereja and Brackets[线段树 区间合并]

    C. Sereja and Brackets time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. echo '.SUFFIXES: .cpp' >> ${OUTPUT_FILE}

    当前makefile或shell内支持文件后缀的类型列表,意思是文件支持.cpp结尾的类型,并且将他,输出到OUTPUT_FILE函数. 见网上有人说: “makefile中 .SUFFIXES: . ...

随机推荐

  1. The Independent JPEG Group's JPEG software Android源码中 JPEG的ReadMe文件

    The Independent JPEG Group's JPEG software========================================== README for rele ...

  2. ubuntu16部署gitlab

    一.gitlab的安装 1. 安装依赖包 $ sudo apt-get update #如无ssh还需安装openssh-server $ sudo apt-get install postfix c ...

  3. PHP自定义函数获取汉字首字母的方法

    使用场景:城市列表等根据首字母排序的场景 function getFirstCharter($str) { if (empty($str)) { return ''; } $fchar = ord($ ...

  4. sequelize 测试

    1.在根目录新建module文件,在文件下新建文件modelhead.js 代码如下: var Sequelize=require("sequelize") var sequeli ...

  5. GCD 学习(四) dispatch_group

    如果想在dispatch_queue中所有的任务执行完成后在做某种操作,在串行队列中,可以把该操作放到最后一个任务执行完成后继续,但是在并行队列中怎么做呢.这就有dispatch_group 成组操作 ...

  6. ZROI2018普转提day7t2

    传送门 分析 首先我们不难想到我们一定可以将每一个点分开算,然后看这个点被几个矩形包含 于是对于位置为$(i,j)$的点它被包含的次数为$i * (n-i+1) * j * (m-j+1)$ 这个式子 ...

  7. About English Web Site Font

    Which font will you choose when develop one website! Actually , I have no idea about this! If you ha ...

  8. Cadence如何自定义快捷键

    第一步:将pcbenv复制到SPB_Data下,并覆盖原来的文件 第二步:打开pcbenv文件,将script和views文件夹以及env复制到cadence安装目录\SPB_16.3\share\p ...

  9. DiscreteFrechetDist

    计算离散的frechet 距离,通过计算两条曲线之间的点的距离,将两条曲线上的点按照距离以及曲线的趋势进行配对,最后根据这些配对的距离选出最后的离散frechet距离(compute discrete ...

  10. Redis实现用户关注功能

    最近项目要涉及到粉丝关注问题,权衡再三还是使用Redis实现比较方便,使用Redis的有序集合可以做到根据关注的时间有序的取出列表,假设我的ID是me,别人的ID是other. 1. 添加关注 添加关 ...