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. Binary Tree Level Order Traversal 解答

    Question Given a binary tree, return the level order traversal of its nodes' values. (ie, from left ...

  2. LeetCode——Reverse Words in a String

    Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...

  3. DAT文件怎样打开

    DAT文件类型主要是"数据"文件.能够是不论什么内容,比方:文字,图形,视频或一般的二进制数据,它并没有统一详细的结构.所以您不能理解它也相应一个用来打开它的应用程序.比方你看到一 ...

  4. C#入门(一):IDE

    设计流程 .NET可视化对象 创建工程的时候,会创建三个文件 Form1.cs Form1.Designer.cs Program.cs 当增加一个控件的时候,会在Form1.Designer.cs增 ...

  5. web推送

    WEB消息推送框架 web-msg-sender是一款web长连接推送框架,采用PHPSocket.IO开发,基于WebSocket长连接通讯,如果浏览器不支持WebSocket则自动转用comet推 ...

  6. org.springframework.beans.factory.BeanCreationException

    org.springframework.beans.factory.BeanCreationException 这个是创建bean的异常. 我所遇到的情况是由下面这个引起的: @Resource an ...

  7. struts1:(Struts重构)构建一个简单的基于MVC模式的JavaWeb

    在构建一个简单的基于MVC模式的JavaWeb 中,我们使用了JSP+Servlet+JavaBean构建了一个基于MVC模式的简单登录系统,但在其小结中已经指出,这种模式下的Controller 和 ...

  8. Shell学习之Shift的用法

        位置参数可以用shift命令左移.比如shift 3表示原来的$4现在变成$1,原来的$5现在变成$2等等,原来的$1.$2.$3丢弃,$0不移动.不带参数的shift命令相当于shift 1 ...

  9. JS判断邮箱格式

    function check(){    var strText=$("#email").val();    var strReg=/^\w+((-\w+)|(\.\w+))*\@ ...

  10. win7笔记本电脑实现wifi共享

    前提条件:win 7系统,有wifi 同dos命令就可实现wifi共享 第一步: netsh wlan start hostednetwork pause 第二步: netsh wlan set ho ...