Sereja and Suffixes

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

Description

Sereja has an array a, consisting of n integers a1a2, ..., 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 a1a2, ..., 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
题解:让求x到n的不同数字的个数;打表,对于m次询问,如果每次都暴力肯定超了,由于n是固定的,所以打下表,从后往前;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
const int MAXN = 1e5+;
class Ary{
public:
int n,m;
int a[MAXN];
int dp[MAXN];
set<int>st;
Ary(int n,int m):n(n),m(m){
for(int i = ; i <= n; i++){
cin >> a[i];
}
}
int work(){
int cnt = ;
for(int i = n; i >= ; i--){
if(!st.count(a[i])){
cnt++;
st.insert(a[i]);
}
dp[i] = cnt;
}
//cout << endl;
}
~Ary(){
//cout << "对象毁灭" << endl;
}
};
int main(){
int n,m;
while(~scanf("%d%d", &n, &m)){
Ary boy(n,m);
int temp;
boy.work();
while(m--){
scanf("%d",&temp);
printf("%d\n",boy.dp[temp]);
}
}
return ;
}

Sereja and Suffixes(思维)的更多相关文章

  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. B. Sereja and Suffixes

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

  3. B. Sereja and Suffixes(cf)

    http://codeforces.com/problemset/problem/368/B B. Sereja and Suffixes time limit per test 1 second m ...

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

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

  5. CodeForces 368B Sereja and Suffixes

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

  6. Sereja and Suffixes

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

  7. cf B. Sereja and Suffixes

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

  8. Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes (思维,字符串)

    题意:给你某个字符串的\(n-1\)个前缀和\(n-1\)个后缀,保证每个所给的前缀后缀长度从\([1,n-1]\)都有,问你所给的子串是前缀还是后缀. 题解:这题最关键的是那两个长度为\(n-1\) ...

  9. Codeforces 1092C Prefixes and Suffixes(思维)

    题目链接:Prefixes and Suffixes 题意:给定未知字符串长度n,给出2n-2个字符串,其中n-1个为未知字符串的前缀(n-1个字符串长度从1到n-1),另外n-1个为未知字符串的后缀 ...

随机推荐

  1. UESTC_邱老师选妹子(二) 2015 UESTC Training for Dynamic Programming<Problem I>

    I - 邱老师选妹子(二) Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Su ...

  2. Windows多线程同步系列之三-----事件对象

    事件是一个内核事件,内核事件是什么呢,我理解也不深入也不好说,暂且理解为一个内核维护的数据类型吧通过内核事件同步主要 的方法是对事件的信号有和无来进行同步. 比如当我们一个线程进入一段临界代码(独占代 ...

  3. HDU 1272 小希的迷宫(并查集) 分类: 并查集 2015-07-07 23:38 2人阅读 评论(0) 收藏

    Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就 ...

  4. 360极速浏览器 HTML5实验室

    360极速浏览器 HTML5实验室 HTML5 实验室

  5. 【转】android 电容屏(一):电容屏基本原理篇

    关键词:android  电容屏 tp  ITO 平台信息:内核:linux2.6/linux3.0系统:android/android4.0 平台:S5PV310(samsung exynos 42 ...

  6. Unity 编辑器扩展自定义窗体

    这次看见Unity还可以自定义弹出窗体,让我很好奇.于是就去网上找文章看了看. 如果想自定义窗体需要把类放入Editor文件夹下面. 代码如下: using UnityEngine; using Un ...

  7. ACM学习-POJ-1125-Stockbroker Grapevine

    菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1125-Stockbroker Grapevine Stockbroker Grapevine Time Li ...

  8. oracle Can't connect to X11 window server using ':0.0' /Checking monitor: must be configured to display at least 256 colors解决方法

    Can't connect to X11 window server using ':0.0' 解决方法 1. 以oracle 用户登陆X window 或者 2. root 身份执行 # xhost ...

  9. cookie 和 session 基本使用 以及 封装

    Cookie: 是一小段文本信息,用户请求页面的时候,在浏览器和服务器之间传递.用户每次访问的时候都会记录cookie,cookie里可以包含用户信息,浏览的历史记录等等:Cookie是由服务器端生成 ...

  10. 使用 Camtasia Recorder显示 “ camtasia an error occurred in the recorder: video codec open failed ”

    这是因为本机没有codec的缘故,可以下载一个:tscc解码器(TechSmith Screen Capture Codec) 2.0.3.0 安装版 http://www.cngr.cn/dir/2 ...