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: anusitt
Problemset: ละลานตา
Language: cpp
Time: 0.008 second
Submitted On: 2026-10-09 20:53:06
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n,k;
cin >> n >> k;
ll a[n],count[100001]={};
queue <ll> q;
for (int i=0;i<n;i++) {
cin >> a[i];
}
int i=0;
int kk=0;
ll ans=0;
while(i<n|| kk >= k) {
if (q.empty()||kk<k) {
q.push(a[i]);
if (count[a[i]]==0) {
kk++;
}
count[a[i]]++;
i++;
}
else {
ans+=n-i+1;
count[q.front()]--;
if (count[q.front()]==0) {
kk--;
}
q.pop();
}
}
cout << ans;
return 0;
}