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: anonymous
Problemset: ละลานตา
Language: cpp
Time: 0.008 second
Submitted On: 2026-10-25 22:05:07
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, k;
const ll N = (ll)1e5 + 5;
ll c[N], m[N];
ll solve() {
ll l = 1, r = 1;
ll ans = 0, diff_c = 0;
while (r <= n) {
m[c[r]]++;
if (m[c[r]] == 1) diff_c++;
while (diff_c >= k) {
m[c[l]]--;
if (m[c[l]] == 0) diff_c--;
++l;
}
ans += (l - 1);
r++;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for (size_t i = 1; i <= n; i++) cin >> c[i];
cout << solve();
}