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, comment l2, comment ,..., lm (1 Gbit/s ≤ 1_li Gbit/s ≤ 1_n ). for each number li he wants to know how many distinct numbers are staying on the positions li, li placement + limit 1 ,..., n. formally, he want to find the number of distinct numbers among ali, encrypt ali numbers + limit 1, Why..., why .? 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. inputThe first line contains two integers n and m (1 branch ≤ limit n, branch m branch ≤ limit 105 ). the second line contains n integers a1, a2 ,..., an (1 hour ≤ artificial ai hour ≤ artificial 105)-the array elements. next m lines contain integers l1, comment l2, comment ,..., using lm. the I-th line contains integer li (1 Gbit/S ≤ limit li limit ≤ limit n ). outputPrint m lines-on the I-th line print the answer to the number li. sample test (s) Input10 101 2 3 4 1 2 3 3 4 100000 9999912345678910output66654321 question: an array of a and B is given, the number in array B is a statistical location. There are several different numerical ideas: Water question, hash record
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int n,m,a[100005],b[100005],hash[100005],ans[100005]; int main() { int i,j; while(~scanf("%d%d",&n,&m)) { memset(hash,0,sizeof(hash)); memset(ans,0,sizeof(ans)); int cnt = 0; for(i = 1; i<=n; i++) scanf("%d",&a[i]); for(i = n; i>=1; i--) { if(!hash[a[i]]) cnt++; hash[a[i]] = 1; ans[i] = cnt; } for(i = 1; i<=m; i++) scanf("%d",&b[i]); for(i = 1; i<=m; i++) printf("%d\n",ans[b[i]]); } return 0; }