Submission
Status:
[P][P][P][P][P][PPPPP]
Subtask/Task Score:
{17/17}{17/17}{17/17}{17/17}{17/17}{17/17}
Score: 100
User: Bestzu
Problemset: ละลานตา
Language: cpp
Time: 0.008 second
Submitted On: 2025-10-17 19:30:06
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N = 1e5 + 10;
vector<int> freq(N);
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int n, k; cin >> n >> k;
vector<int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
int l = 0, r = 0;
int cnt = 0;
long long int ans = 0;
while(r < n) {
if(freq[a[r]] == 0) cnt++;
freq[a[r]]++;
r++;
while(cnt >= k) {
freq[a[l]]--;
if(freq[a[l]] == 0) {
cnt--;
}
l++;
}
ans += l;
}
cout << ans << endl;
return 0;
}