Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- int main()
- {
- vector<int> v;
- map<int,int> mapa;
- vector< map<int,int> > DP;
- int n, q;
- cin>>n>>q;
- v.resize(n);
- DP.resize(n+1);
- for(int i=0; i<n; i++)
- cin>>v[i];
- DP[0] = mapa;
- for(int i=1; i<=n; i++)
- {
- mapa[ v[i-1] ]++;
- DP[i] = mapa;
- }
- mapa.clear();
- int a, b;
- for(int i=0; i<q; i++)
- {
- cin>>a>>b;
- mapa = DP[b];
- for(auto j:DP[a-1])
- mapa[ j.first ] -= j.second;
- int c = 0;
- for(auto j:mapa)
- {
- if (j.second == 2)
- c++;
- }
- cout<<c<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment