• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #215 Div2 B

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

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 test(s)
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
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <vector>
 4 #include <set>
 5 #include <cstring>
 6 #include <string>
 7 #include <map>
 8 #include <cmath>
 9 #include <ctime>
10 #include <algorithm>
11 #include <queue>
12 
13 using namespace std;
14 #define INF 0x7fffffff
15 #define maxm 1001
16 #define mp make_pair
17 #define pb push_back
18 #define rep(i,n) for(int i = 0; i < (n); i++)
19 #define re return
20 #define fi first
21 #define se second
22 #define sz(x) ((int) (x).size())
23 #define all(x) (x).begin(), (x).end()
24 #define sqr(x) ((x) * (x))
25 #define sqrt(x) sqrt(abs(x))
26 #define y0 y3487465
27 //#define y1 y8687969
28 //#define fill(x,y) memset(x,y,sizeof(x))
29 
30 typedef vector<int> vi;
31 typedef long long ll;
32 typedef long double ld;
33 typedef double D;
34 typedef pair<int, int> ii;
35 typedef vector<ii> vii;
36 typedef vector<string> vs;
37 typedef vector<vi> vvi;
38 
39 template<class T> T abs(T x) { re x > 0 ? x : -x; }
40 
41 const int maxn = 110005;
42 
43 int n, m, t, s, k, x;
44 int a[maxn], b[maxn],vis[maxn];
45 int main(){
46     scanf("%d%d", &n, &k);
47     for (int i = 0; i < n; i++)scanf("%d", &a[i]);
48     b[n - 1] = 1;
49     vis[a[n - 1]] = 1;
50     for (int i = n - 2; i >= 0; i--){
51         if (vis[a[i]])b[i] = b[i + 1];
52         else b[i] = b[i + 1] + 1;
53         vis[a[i]] = 1;
54     }
55     while (k--){
56         scanf("%d", &x);
57         printf("%d\n", b[x - 1]);
58     }
59     return 0;
60 }
View Code
posted @ 2013-11-27 01:46  HaibaraAi  阅读(107)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3