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. Android Studio 搭配 Tortoise SVN 安装问题汇总

    (1)Android studio 中想要使用SVN,但是在安装 1.9版本的SVN,会报SVN is too old(实际是太新了)的错误.所以只能下载1.8以下版本 (2)安装svn时,需要手动选 ...

  2. 【总结整理】arcgis js api的Map类

    关于ArcGis for javascrept之Map类   ArcGis for javascrept_ESRI_Map类:  1. 构造方法:esri.Map(); 参数: extent 如果设置 ...

  3. ENCODE:DNA 分子元件的百科全书

    ENCODE(DNA分子元件的百科全书)是由国家人类基因研究所(NHGRI)资助的一个国际研究联盟, 该联盟的目标是:建立一份综合的人类基因组功能元件的清单,这些基本元件包括那些直接作用蛋白质和RNA ...

  4. GCD学习(七) dispatch_apply

    dispathc_apply 是dispatch_sync 和dispatch_group的关联API.它以指定的次数将指定的Block加入到指定的队列中.并等待队列中操作全部完成. NSArray ...

  5. p3163 [CQOI2014]危桥

    传送门 分析 代码 #include<iostream> #include<cstdio> #include<cstring> #include<string ...

  6. Luogu 4777 【模板】扩展中国剩余定理(EXCRT)

    复习模板. 两两合并同余方程 $x\equiv C_{1} \ (Mod\ P_{1})$ $x\equiv C_{2} \ (Mod\ P_{2})$ 把它写成不定方程的形式: $x = C_{1} ...

  7. leetcode 6 ZigZag Converesion

    class Solution { public: string convert(string s, int nRows) { if (nRows <= 1) return s; string r ...

  8. WebGoat系列实验Access Control Flaws

    WebGoat系列实验Access Control Flaws Using an Access Control Matrix 在基于角色的访问控制策略中,每个角色都代表了一个访问权限的集合.一个用户可 ...

  9. @RestControllerAdvice注解使用

    在spring 3.2中,新增了@ControllerAdvice,@RestControllerAdvice 注解,可以用于定义@ExceptionHandler.@InitBinder.@Mode ...

  10. NMS---非极大值抑制

    在物体检测中,NMS(Non-maximum suppression)应用十分广泛,其目的是为了消除多余的框,找到最佳的物体检测的位置.在RCNN系列算法中,会从一张图片中找出很多个候选框(可能包含物 ...