Pagini recente » winners31bis | Cod sursa (job #543616) | Cod sursa (job #79081) | Cod sursa (job #1379406) | Cod sursa (job #716126)
Cod sursa(job #716126)
#include<iostream>
#include<fstream>
#include<vector>
#define M 666013
using namespace std;
ifstream in("secv5.in");
ofstream out("secv5.out");
unsigned int n,l,u,x[1000010],st,dr;
char s[20];
vector<pair<int,int> > h[M];
vector<pair<int,int> >::iterator it;
inline void add(int el, int val) {
for(it=h[el%M].begin(); it!=h[el%M].end(); ++it)
if(it->first==el) {
(it->second)+=val;
return;
}
h[el%M].push_back(pair<int,int>(el,val));
}
inline int find(int el) {
for(it=h[el%M].begin(); it!=h[el%M].end(); ++it)
if(it->first==el)
return it->second;
return 0;
}
inline unsigned int sol(unsigned int dim) {
for(int i=0;i!=M;++i)
h[i].clear();
if(!dim)
return 0;
unsigned int sol=0,nr=0;
for(st=1, dr=1; dr<=n; ++dr) {
if(!find(x[dr]))
++nr;
add(x[dr],1);
while(nr>dim) {
if(find(x[st])==1)
--nr;
add(x[st],-1);
++st;
}
sol += dr - st + 1;
}
return sol;
}
int main() {
unsigned int i,xx;
in >> n >> l >> u;
in.getline(s,30);
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;
}