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 ;
}

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

  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

    B. Sereja and Suffixes time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. cf B. Sereja and Suffixes

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

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

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

  6. CodeForces 368B Sereja and Suffixes

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

  7. Sereja and Suffixes

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

  8. CF 314 E. Sereja and Squares

    E. Sereja and Squares http://codeforces.com/contest/314/problem/E 题意: 给你一个擦去了部分左括号和全部右括号的括号序列,括号有25种 ...

  9. CF 314C Sereja and Subsequences(树状数组)

    题目链接:http://codeforces.com/problemset/problem/314/C 题意:给定一个数列a.(1)写出a的不同的所有非下降子列:(2)定义某个子列的f值为数列中各个数 ...

随机推荐

  1. Caffe2:python -m caffe2.python.operator_test.relu_op_test

    1. 进行语句测试时候,出现问题, 设置环境变量CUDA_VISIBLE_DEVICES 参考: cuda设置指定可见方法 在/etc/profile文件或者-/.bashrc末尾添加以下行: exp ...

  2. (原创)HyperPacer使用技巧之集合点设置

    版权声明:本文为原创文章,转载请先联系并标明出处 性能测试中,我们可以模拟最真实的用户操作来建立性能模型,但是这种模拟是相对的.譬如12306网站春运开始后每一天都是高峰,这种高负载情况会持续一至两个 ...

  3. cordova插件分类

    1.android自动更新功能所需插件 cordova plugin add https://github.com/whiteoctober/cordova-plugin-app-version.gi ...

  4. Address space layout randomization

    Address space layout randomization (ASLR) is a computer security technique involved in preventing ex ...

  5. php银联支付

    简介 PHP银联支付 流程 1.注册 银联 - 技术开发平台和商户服务平台 https://open.unionpay.com 注意:注册时建议使用IE浏览器,之前注册时插件老是用不了,使用IE10以 ...

  6. ubuntu14.04远程软件VNC的安装、设置方法

    ubuntu中VNCX11開機啟動保持靜默狀態方法: 1首先安裝vncx11. 2.設置vnc密碼,會自動保存在/home/test/.vnc/passwd中 3.將密碼複製到/etc中 4.在/et ...

  7. 【转载】xShell5 利用 sftp 在本地和服务器之间传输文件

    sftp是Secure File TransferProtocol的缩写,安全文件传送协议.可以为传输文件提供一种安全的加密方法.sftp与 ftp有着几乎一样的语法和功能.SFTP为 SSH的一部分 ...

  8. 关于在JSP页面中为什么一定要用${pageContext.request.contextPath}来获取项目路径,而不能用${request.contextPath}?

    这里的疑问在于pageContext和request都是JSP中的内置对象之一,为什么不直接用${request.contextPath}来获取项目路径? 出现这种疑问,其实是将JSP的内置对象和EL ...

  9. kendo grid结合ajax功能

    我感觉使用ajax结合表格绑定效率更好一些,可以灵活的控制点击前后的事件,现在grid前后的事件我不能控制

  10. js移除style属性

    这个属性是通过   div.style.color="red"   这种类似添加的,想要添加重置函数,使用div.removeAttribute("style" ...