B. Sereja and Suffixes(cf)
http://codeforces.com/problemset/problem/368/B
1 second
256 megabytes
standard input
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.
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).
Print m lines — on the i-th line print the answer to the number li.
10 10
1 2 3 4 1 2 3 4 100000 99999
1
2
3
4
5
6
7
8
9
10
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 ;
}
最新文章
- 使用css打造形形色色的形状!
- Week 1:2015/4/27~2015/5/3
- CodeForce Round#49 untitled (Hdu 5339)
- Linux信号基础
- web app变革之rem(手机屏幕实现全适配)
- Apple Watch应用开发经验谈:我遇到的那些坑
- 连接数据库超时设置autoReconnect=true
- AsyncTask实现下载图片
- DropdownList的处理总结
- [推荐]ORACLE PL/SQL编程详解之一:PL/SQL 程序设计简介(千里之行,始于足下)
- Java初学练习答案(循环)
- Tomcat8远程访问manager,host-manager被拒绝403
- Initialization error SQL*Net not properly installed
- Editorial Board 、co-editor、ediitor、editor-in-chief的区别
- 一次完整的http请求过程
- CentOS的el5, el6, el7代表什么
- opencv: 线性拟合
- 黄聪:解决Bootstrap模态框(modal)弹出后页面跑到顶部的办法
- Python_Xlrd&;Xlwt
- java实现版本比较
热门文章
- (转)Java任务调度框架Quartz入门教程指南(三)任务调度框架Quartz实例详解深入理解Scheduler,Job,Trigger,JobDetail
- Django REST framework 初识
- 直流电机PWM调速系统中控制电压非线性研究_控制元件_工业自动化控制_文章
- UTL
- pandas - 案例(美国各州人口普查)
- hdu 5171 GTY&#39;s birthday gift
- bupt summer training for 16 #8 ——字符串处理
- BUPT2017 wintertraining(16) #9
- Entity Framework Connection String不保留密码的方法
- xth的第 12 枚硬币(codevs 1366)