Sereja and Suffixes

Sereja and Suffixes J- SerejaandSuffixesTimeLimit:1000MS     MemoryLimit:262144KB     64bitIOFormat:%I64d&%I64uSubmit StatusDescriptionSerejahasanarray a,consistingof n integers a1, a2, …, …

 

J – Sereja and Suffixes

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

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 Input

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

 

 

 

 

 

题目分析:

这个题目应该是好读懂的,

 

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

 

 

10  10

10  这个数列有10个元素

10  有10个数据测试

1  数列从第一个数开始到最后有多少个不同的数 6(自己数一下)

2  数列从第二个数开始到最后有多少个不同的数 6

3  数列从第三个数开始到最后有多少个不同的数 6

.

7  数列从第7  个数开始到最后有 多少个不同的数 4

.

10 数列从第10个数开始到最后有多少个不同的数 1

 

 

 

#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100010
using namespace std;
int a[maxn],b[maxn],c[maxn];
int main()
{
	int n,m;
	while(~scanf("%d%d",&n,&m))
	{
		
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		int ans=0;
		for(int i=n-1;i>=0;i--)
		{
			if(!b[a[i]])
				ans++;
				b[a[i]]=1;
				c[i]=ans;
		}
//		for(int i=0;i<n;i++)
//			printf("%d ",c[i]);
//			printf("\n");
		int t;
		for(int i=0;i<m;i++)
		{
			scanf("%d",&t);
			printf("%d\n",c[t-1]);
		}
	}
	return 0;
}

 

 

 

 

 

 

 

 

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/219608.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • headless CMS_model view controller

    headless CMS_model view controller目录介绍HeadlessCMS什么是HeadlessCMS?HeadlessCMS的优点HeadlessCMS解决方案的局限性使用HCMS的缺点HCMS的局限性何时何地使用HeadlessCMS?RawCMS:构建自己的HeadlessCMS为什么另一个HeadlessCMS?RawCms特征选择架构服务层认证Lambda表…

    2022年11月2日
  • vue生成时间戳_hive时间戳转换日期

    vue生成时间戳_hive时间戳转换日期1.首先定义好一个工具类:2.在对应的文件中引入该文件:3.局部注册过滤器:

    2022年10月21日
  • Vue生命周期(11个钩子函数)「建议收藏」

    Vue生命周期生命周期初识生命周期详解(八个钩子函数)生命周期生命周期:Vue是一个构造函数,当执行执行这个函数时,相当于初始化vue实例;在创建实例过程中,需要设置数据监听,编译模板,将实例挂载到DOM上,数据更新能够让DOM也更新,在这个初始化,又会不同阶段默认调用一些函数执行,这些函数就是生命周期的钩子函数;生命周期钩子函数生命周期钩子函数,让够让咱们…

    2022年4月6日
  • 遍历ArrayList,并删除某些元素的方法实现「建议收藏」

    遍历ArrayList,并删除某些元素的方法实现「建议收藏」本文是根据https://blog.csdn.net/qq_32575047/article/details/78902254的帖子进行整理的,在此感谢一下。题目:一个ArrayList对象aList中存有若干个字符串元素,现欲遍历该ArrayList对象,删除其中所有值为”abc”的字符串元素,请用代码实现。publicclassTest1{public…

    2022年9月30日
  • 序列(两)密钥索引、桶排序、位图、失败者树(照片详细解释–失败者树)「建议收藏」

    序列(两)密钥索引、桶排序、位图、失败者树(照片详细解释–失败者树)「建议收藏」序列(两)以上排序算法都有一个性质:在排序的终于结果中,各元素的次序依赖于它们之间的比較。我们把这类排序算法称为比較排序。不论什么比較排序的时间复杂度的下界是nlgn。下面排序算法是用运算而不是比較来

    2022年7月1日
  • SD卡、TF卡、MMC卡、emmc、sdio扫盲

    SD卡、TF卡、MMC卡、emmc、sdio扫盲一、sd卡、tf卡,mmc卡的区别:共同点:SDTFMMC都是在MMC基础上演化发展不同的规范,比如物理尺寸,封装,电压,管脚,位宽,时钟信号等不同,但都使用相同的总线规范。MMC(multiMediacard)是一种通信协议,支持两种模式SPI和MMC,定义了诸如卡的形态、尺寸、容量、电气信号、和主机之间的通信协议等。SD卡是SecureDigitalCard的英文缩写,直译就是“安全数字卡”。SD卡是(securedigitalmemorycar…

    2022年5月12日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号