AlenAntonelli

Poklon

Jun 27th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     vector<int> v;
  9.     map<int,int> mapa;
  10.     vector< map<int,int> > DP;
  11.     int n, q;
  12.     cin>>n>>q;
  13.    
  14.     v.resize(n);
  15.     DP.resize(n+1);
  16.    
  17.     for(int i=0; i<n; i++)
  18.         cin>>v[i];
  19.    
  20.     DP[0] = mapa;
  21.     for(int i=1; i<=n; i++)
  22.     {
  23.         mapa[ v[i-1] ]++;
  24.         DP[i] = mapa;
  25.     }
  26.     mapa.clear();
  27.    
  28.     int a, b;
  29.     for(int i=0; i<q; i++)
  30.     {
  31.         cin>>a>>b;
  32.        
  33.         mapa = DP[b];
  34.        
  35.         for(auto j:DP[a-1])
  36.             mapa[ j.first ] -= j.second;
  37.        
  38.         int c = 0;    
  39.         for(auto j:mapa)
  40.         {
  41.             if (j.second == 2)
  42.                 c++;
  43.         }
  44.         cout<<c<<endl;
  45.     }
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment