http://codeforces.com/problemset/problem/368/B

B. Sereja and Suffixes
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 li, li + 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.

Sample test(s)
Input
10 10
1 2 3 4 1 2 3 4 100000 99999
1
2
3
4
5
6
7
8
9
10
Output
6
6
6
6
6
5
4
3
2
1
 #include <stdio.h>
#include <string.h>
const int N=;
int hash[N],f[N],a[N],l[N];
int main()
{
int n,m,cnt = ;
scanf("%d %d",&n,&m);
memset(hash,,sizeof(hash));
for (int i = ; i <= n; i++)
scanf("%d",&a[i]);
for (int i = ; i <= m; i++)
scanf("%d",&l[i]);
for (int i = n; i >= ; i--)
{
hash[a[i]]++;
if (hash[a[i]]==)
cnt++;
f[i] = cnt;//表示从i到n的不同的元素个数
}
for (int i = ; i <= m; i++)
printf("%d\n",f[l[i]]);
return ;
}

最新文章

  1. 使用css打造形形色色的形状!
  2. Week 1:2015/4/27~2015/5/3
  3. CodeForce Round#49 untitled (Hdu 5339)
  4. Linux信号基础
  5. web app变革之rem(手机屏幕实现全适配)
  6. Apple Watch应用开发经验谈:我遇到的那些坑
  7. 连接数据库超时设置autoReconnect=true
  8. AsyncTask实现下载图片
  9. DropdownList的处理总结
  10. [推荐]ORACLE PL/SQL编程详解之一:PL/SQL 程序设计简介(千里之行,始于足下)
  11. Java初学练习答案(循环)
  12. Tomcat8远程访问manager,host-manager被拒绝403
  13. Initialization error SQL*Net not properly installed
  14. Editorial Board 、co-editor、ediitor、editor-in-chief的区别
  15. 一次完整的http请求过程
  16. CentOS的el5, el6, el7代表什么
  17. opencv: 线性拟合
  18. 黄聪:解决Bootstrap模态框(modal)弹出后页面跑到顶部的办法
  19. Python_Xlrd&amp;Xlwt
  20. java实现版本比较

热门文章

  1. (转)Java任务调度框架Quartz入门教程指南(三)任务调度框架Quartz实例详解深入理解Scheduler,Job,Trigger,JobDetail
  2. Django REST framework 初识
  3. 直流电机PWM调速系统中控制电压非线性研究_控制元件_工业自动化控制_文章
  4. UTL
  5. pandas - 案例(美国各州人口普查)
  6. hdu 5171 GTY&#39;s birthday gift
  7. bupt summer training for 16 #8 ——字符串处理
  8. BUPT2017 wintertraining(16) #9
  9. Entity Framework Connection String不保留密码的方法
  10. xth的第 12 枚硬币(codevs 1366)