Pagini recente » Cod sursa (job #3335869) | Cod sursa (job #3356044) | Cod sursa (job #3306231) | Cod sursa (job #3329623) | Cod sursa (job #3351885)
#include <fstream>
#include <vector>
#include <unordered_map>
using namespace std;
ifstream fin("secv5.in");
ofstream fout ("secv5.out");
unordered_map<unsigned int, int> frU, frL;
vector<unsigned int> a;
int distinctU = 0, distinctL = 0;
int n, L, U;
int main() {
fin >> n >> L >> U;
a.resize(n);
for (int i = 0; i < n; i++) fin >> a[i];
long long total = 0;
int stU = 0, stL = 0;
for (int right = 0; right < n; right++) {
if (frU[a[right]] == 0) distinctU++;
frU[a[right]]++;
if (frL[a[right]] == 0) distinctL++;
frL[a[right]]++;
while (distinctU > U) {
frU[a[stU]]--;
if (frU[a[stU]] == 0) distinctU--;
stU++;
}
while (distinctL > L - 1) {
frL[a[stL]]--;
if (frL[a[stL]] == 0) distinctL--;
stL++;
}
if (distinctU >= L) {
total += (stL - stU);
}
}
fout << total << endl;
return 0;
}