B. Sereja and Suffixes

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

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

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

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

Sample Output

6
6
6
6
6
5
4
3
2
1

HINT

题意

n个数,m次询问

每次询问,问你[l,n]有多少不同的数字

题解:

用map就好了

我们离线做

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 1050005
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
//**************************************************************************************int ans[maxn];
int a[maxn];
map<int,int> H;
int flag=0;
int main()
{int n=read(),m=read();for(int i=1;i<=n;i++){a[i]=read();H[a[i]]++;if(H[a[i]]==1)flag++;}for(int i=1;i<=n;i++){ans[i]=flag;H[a[i]]--;if(H[a[i]]==0)flag--;}for(int i=1;i<=m;i++){int x=read();printf("%d\n",ans[x]);}
}

转载于:https://www.cnblogs.com/qscqesze/p/4619140.html

Codeforces Round #215 (Div. 2) B. Sereja and Suffixes map相关推荐

  1. Codeforces Round #215 (Div. 2) D. Sereja ans Anagrams

    http://codeforces.com/contest/368/problem/D 题意:有a.b两个数组,a数组有n个数,b数组有m个数,现在给出一个p,要你找出所有的位置q,使得位置q  q+ ...

  2. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes kmp + dp

    传送门 文章目录 题意: 思路: 题意: 思路: 通过完美子串的定义,我们不难发现满足条件的子串就是kmpkmpkmp中ne[n]ne[n]ne[n]不断向前跳得到的串,现在问题就是如何求这些前缀串在 ...

  3. Codeforces Round #223 (Div. 2): E. Sereja and Brackets(线段树)

    题意: 给你一个括号序列和m次询问,每次询问区间[L, R]内匹配的括号个数 思路: 这道题线段树只用来维护区间最小值,所以理论上RMQ也可以,主要是要稍微推一下 设左括号为1,右括号为-1,s[]为 ...

  4. Codeforces Round #223 (Div. 2): C. Sereja and Prefixes(二分+递归)

    题意: 你有一个序列,一开始为空,之后进行m次操作,操作有两种: 1 x:在当前序列后面添加一个数x 2 x, y:将序列的前x个数复制y遍接序列后面(x<10000) 之后n次询问,每次询问位 ...

  5. Codeforces Round #486 (Div. 3) C Equal Sums (map+pair)

    传送门 •题意 给k个数列,从中k个数列中找出任意2个数列 i ,j 使得数列i删除第x个数,和数列j删除第y个数的和相等 若存在,输出 i ,x 和 j,y •思路 每个数列之间的联系为数列的和之间 ...

  6. Codeforces Round #807 (Div. 2) A - D

    Codeforces Round #807 (Div. 2) 提交情况 参考 Codeforces Round #807 (Div. 2) A~E A. Mark the Photographer 标 ...

  7. Educational Codeforces Round 112(Div.2) ABC题解

    D题好像可以做一做,挖个坑以后做好了来填(doge Educational Codeforces Round 112(Div.2) 题目列表 1.A 2.B 3.C 1.A 原题链接 题目大意 有三种 ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  10. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

最新文章

  1. php 访问类成员,PHP类成员的访问方式和权限_PHP教程
  2. 生物什么时候学公式计算机,高考生物重要规律性关系及公式精华归纳,转走吧!...
  3. vivo Y93s的USB调试模式在哪里,打开vivo Y93sUSB调试模式的步骤
  4. JAVA接口的访问权限_Java中访问权限-类和接口
  5. php 回调通知 连连支付_php怎么写连连支付退款
  6. spring----Bean的生命周期和循环依赖
  7. MFC中文件打开与保存
  8. (二十)ArcGIS JS 加载WMTS服务(超图示例)
  9. 业务逻辑全写在sql_12306的业务逻辑很复杂么?一条SQL语句搞不定?
  10. 08TensorFlow2.0基础--8.2创建张量
  11. 疯狂ios讲义之实例:通过旋转手势旋转图片
  12. PVD桌面怎样重新调整personal vDisks大小
  13. 2018年最新北风网人工智能视频教程(完整版)
  14. 【cofface】酷派手机升级助手Coolpad Download Assistant图文教程
  15. 【转】扫盲 同步利器、分布式网盘--BT Sync
  16. 英语钻石法则(一)-----句子中心论
  17. 纯干货!信贷行业电话销售员一定要掌握的电话沟通话术
  18. 使用php实现自动获取一个获取文章标题生成主题关键词功能源码
  19. 《变形金刚》真人电影知识普及贴-转帖
  20. 基于pycharts的白蛇2影评分析

热门文章

  1. python源码中的学习笔记_第10章_面向对象的特征、特殊方法与属性、以及深浅拷贝
  2. 数据结构与算法 第一章 引入
  3. python时间操作代码
  4. python的类与继承
  5. AI顶会论文“趋势”:对新方法的过度关注,与现实问题的脱节
  6. 超8千Star,火遍Github的Python反直觉案例集!
  7. argparse及logging的相关用法
  8. 如此多的深度学习框架,为什么我选择PyTorch?
  9. 6.6 BERT家族02——sentence-BERT、BioBERT
  10. [交叉验证]机器学习中分类器的选择