fork download
  1. // created by : eaugene
  2. // time : 17:04:26 OCT 17 , 2018
  3.  
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. int main() {
  9. // your code goes here
  10.  
  11. int n=0,m=0;
  12. cin>>n>>m;
  13.  
  14. int a[n],b[m];
  15.  
  16. for(int i=0;i<n;i++)
  17. {
  18. cin>>a[i];
  19. }
  20.  
  21. int x[100001];
  22. memset(x,0,sizeof(x));
  23.  
  24. int ans[n+2];
  25. memset(ans,0,sizeof(ans));
  26. for(int i=n-1;i>=0;i--)
  27. {
  28. int j=a[i];
  29. if(x[j]==0)
  30. {
  31. ans[i+1]=1;
  32. //x[j]++;
  33. }
  34. x[j]++;
  35. // cout<<ans[i+1]<<"^^^^";
  36. ans[i+1]+=ans[i+2];
  37. // cout<<ans[i+1]<<endl;
  38. }
  39. int k;
  40. for(int i=0;i<m;i++)
  41. {
  42. cin>>k;
  43. cout<<ans[k]<<" ";
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0s 15496KB
stdin
7 10
1 3 8 6 2 2 7
4 2 6 3 4 4 6 2 7 4
stdout
3 5 2 4 3 3 2 5 1 3