Sereja and Suffixes

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

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全家桶1年46,售后保障稳定

 

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 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.

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

Jetbrains全家桶1年46,售后保障稳定

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)
上一篇 2025年7月5日 下午4:43
下一篇 2025年7月5日 下午5:22


相关推荐

  • 考研数学二常用公式_考研数学写公式有分吗

    考研数学二常用公式_考研数学写公式有分吗面(体)积公式一元二次方程基础极坐标方程与直角坐标转换切线与法线方程因式分解公式阶乘与双阶乘函数的奇偶性排列组合等差数列等比数列常用数列前n项和不等式三角函数公式诱导公式平方关系两角和与差的三角函数积化和差公式和差化积公式倍角公式半角公式万能公式其他公式反三角函数恒等式极限相关公式数列极限递推式重要极限公式常用等价无穷小1^∞型导数相关公式导数定义微分定义连续,可导及可微关系一元函数多元函数导数四则运算复合函数求导反函数求导参数方程

    2022年8月11日
    27
  • UML——类图

    UML——类图UML——类图

    2022年4月24日
    46
  • 离散数学知识点整理

    离散数学知识点整理1 群满足如下条件的二元运算的代数结构满足封闭性有单位元有逆元满足结合律 2 阿贝尔群 交换群或加群 它除了满足一般的群公理 即 运算的结合律满足封闭性有单位元所有的元素都有逆元还满足 交换律因为阿贝尔群的群运算满足交换律和结合律 群元素乘积的值与乘法运算时的次序无关

    2026年3月18日
    2
  • 欧几里得距离、曼哈顿距离和切比雪夫距离

    欧几里得距离、曼哈顿距离和切比雪夫距离闵可夫斯基距离 1 p 为 2 时是欧几里得距离 两个点之间的距离 也即通常情况下 我们所计算的距离 n 维空间中的欧式距离的计算公式为 2 p 为 1 时是 nbsp 曼哈顿距离 两个点在标准坐标系上的绝对轴距总和 在 2 维空间中的计算公式为 3 切比雪夫距离 各坐标数值差的最大值 在 2 维空间中的计算公式为

    2025年11月16日
    6
  • Python缩进规则_python任意代码都可以缩进

    Python缩进规则_python任意代码都可以缩进具有相同缩进的代码被视为代码块。缩进在Python中具有严格的习惯写法:4个空格,不要使用Tabif语句后接表达式,然后用:表示代码块的开始。

    2022年10月13日
    7
  • 大数据——Flume+Kafka+Flume整合模式

    大数据——Flume+Kafka+Flume整合模式创建kafka主题#启动kafka服务kafka-server-start.sh/opt/software/kafka280cala212/conf/kraft/server.properites#创建主题#topic主题名test01#partitions分区数1#replication-factor备份数量1kafka-topics.sh–create–topictest01–partitions1–replication-factor1…

    2022年6月23日
    44

发表回复

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

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