Pagini recente » Cod sursa (job #1647447) | Cod sursa (job #2402026) | Cod sursa (job #1040576) | Cod sursa (job #2338805) | Cod sursa (job #716113)
Cod sursa(job #716113)
#include<iostream>
#include<fstream>
#include<ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
ifstream in("secv5.in");
ofstream out("secv5.out");
unsigned int n,l,u,x[1000010],st,dr;
char s[20];
hash_map<unsigned int,unsigned int> h;
inline unsigned int sol(unsigned int dim) {
h.clear();
if(!dim)
return 0;
unsigned int sol=0,nr=0;
for(st=1, dr=1; dr<=n; ++dr) {
if(!h[x[dr]])
++nr;
h[x[dr]]++;
while(nr>dim) {
if(h[x[st]]==1)
--nr;
h[x[st]]--;
++st;
}
sol += dr - st + 1;
}
return sol;
}
int main() {
unsigned int i,xx;
in >> n >> l >> u;
for(i=1;i<=n;++i) {
in.getline(s,30);
xx = 0;
for(int j = 0; s[j]!=0; ++j)
xx = xx * 10 + s[j] - '0';
x[i] = xx;
}
out << sol(u) - sol(l-1) << "\n";
return 0;
}