Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int a[123459],n,k;
- unordered_map<int,int> M;
- int main()
- {
- int total,nrD;
- cin>>n>>k;
- for(int i=0;i<n;++i)
- cin>>a[i];
- nrD=0;
- for(int i=0;i<k;++i)
- {
- ++M[a[i]];
- if(M[a[i]]==1)
- ++nrD;
- if(M[a[i]]==2)
- --nrD;
- }
- total=nrD;
- for(int i=k;i<n;++i)
- {
- --M[a[i-k]];
- if(M[a[i-k]]==0)
- --nrD;
- if(M[a[i-k]]==1)
- ++nrD;
- ++M[a[i]];
- if(M[a[i]]==1)
- ++nrD;
- if(M[a[i]]==2)
- --nrD;
- total+=nrD;
- }
- cout<<total;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement