CF #215DIV2: B. Sereja and Suffixes

Source: Internet
Author: User

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;  }  

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.