Preview:
#include<bits/stdc++.h>
#include <iostream> 
#include <vector>
#include <utility> 
#include <iterator>
#include <algorithm> 
#include <deque> 
#include <cmath> 
#include <string>
using namespace std; 
//mmaxx=INT_MIN ; 
int main()
{      
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
      int N,M ; 
      cin>>N>>M ;  
      vector<int>C(N) ;
      int v[1000000]={0} ; 
      int arr[N]={0} ; 
      int count=0 ; 
       
      for(int i=0 ;i<N ;i++){ 
          cin>>C[i] ;
          v[C[i]]++ ; 
          if(v[C[i]]==2){
               arr[i]=1 ; 
          }
      } 
      
      
      
      
      
      while(M--){
          int x; 
          cin>>x ; 
          x-=1 ;
          count=N-x ;
          for(int i=x ;i<N ;i++){
              if(arr[i]==1){
                  count-=1;
              }
          }
      } 
      cout<<count<<endl;
      
        
        
        
    return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter