Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int MN = 1e5+5;
- long long N, M, i, x, hsh, ans, lol, cnt[MN], pw[MN]={1};
- map<long long,int> mp;
- int main(){
- mp[0] ++;
- for(i=1;i<MN;i++) pw[i]=pw[i-1]*100003;
- for(scanf("%lld%lld",&N,&M),i=1;i<=N;i++){
- scanf("%lld",&x);
- cnt[x] ++;
- if(cnt[x] == 1) lol ++;
- if(lol == M){
- hsh = 0;
- for(int j=1;j<=M;j++){
- cnt[j] --;
- if(!cnt[j]) lol--;
- hsh += cnt[j]*pw[j];
- }
- }
- else{
- hsh -= (cnt[x]-1)*pw[x];
- hsh += cnt[x]*pw[x];
- }
- ans += mp[hsh];
- mp[hsh]++;
- }
- printf("%lld\n",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement