Pagini recente » Cod sursa (job #1696490) | Cod sursa (job #694872) | Cod sursa (job #2473469) | Istoria paginii runda/concurstreiore | Cod sursa (job #1687033)
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream fin ("secv5.in");
ofstream fout ("secv5.out");
const int nmax = 1<<20 + 5;
long long v[nmax], n;
long long Count(long long x) {
unordered_map<long long,long long> h;
long long sol=0, last=1, i;
for(i=1; i<=n; i++) {
h[v[i]]++;
while(h.size() > x) {
h[v[last]]--;
if(h[v[last]]==0) h.erase(v[last]);
last++;
}
sol+=(i-last+1);
}
return sol;
}
int main() {
ios_base::sync_with_stdio(false);
long long i, l, u;
fin >> n >> l >> u;
for(i=1; i<=n; i++)
fin >> v[i];
fout << Count(u)-Count(l-1);
fin.close();
fout.close();
return 0;
}