0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-18 21:11:57 +00:00
OI-codes/S2OJ/1558/1558.cpp

40 lines
704 B
C++
Raw Normal View History

#include <iostream>
#include <unordered_map>
#include <unordered_set>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5;
int n, m, a[N];
long long ans;
std::unordered_set<int> set;
std::unordered_map<int, int> map;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1, j = 0; i <= n - m + 1; i++) {
while (j < n && set.size() < m) {
set.insert(a[++j]);
map[a[j]]++;
}
if (set.size() == m) ans += n - j + 1;
if (!--map[a[i]]) set.erase(a[i]);
}
cout << ans << endl;
return 0;
}