Submission
Status:
[P][P][P][P][P][PPPPP]
Score: 100
User: Ecir
Problemset: ละลานตา
Language: cpp
Time: 0.008 second
Submitted On: 2025-03-22 20:42:27
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
#define twod array<ll,2>
bool p[15009];
vector<int> prime;
// https://firefly.gchan.moe/problemset/ku01_64o2_many
int arr[100009];
int mp[100009];
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,lim;cin >> n >> lim;
for(int i=1;i<=n;i++) cin >> arr[i];
ll ans=0;
int cnt=0;
int l=0;
for(int i=1;i<=n;i++){
if(mp[arr[i]]==0) cnt++;
mp[arr[i]]++;
if(cnt>=lim){
ans+=n-i+1;
// cout << i << " ";
while(l<i){
l++;
mp[arr[l]]--;
if(mp[arr[l]]==0){
cnt--;
break;
}
ans+=n-i+1;
}
}
}
cout << ans;
return 0;
}