Pagini recente » Cod sursa (job #2229157) | Cod sursa (job #1334644) | Cod sursa (job #268035) | Cod sursa (job #1298304) | Cod sursa (job #852007)
Cod sursa(job #852007)
#include<fstream>
#include<cstring>
#include<vector>
#include<algorithm>
#define dim 1<<20
using namespace std;
ifstream f("secv5.in");
ofstream g("secv5.out");
vector < pair < unsigned long long ,unsigned long long > >s;
unsigned long long normalizare,i,j,n,u,l,v[dim],fr[dim];
long long sub(int X) {
unsigned long long ans=0;
memset(fr,0,sizeof(fr));
unsigned long long i=0;unsigned long long j=0;
unsigned long long nr=0;
for(;j<n;++j) {
if(fr[v[j]]==0)
++nr;
++fr[v[j]];
while(nr>X) {
--fr[v[i]];
if(!fr[v[i]])
--nr;
++i;
}
ans+=j-i+1;
}
return ans;
}
int main () {
f>>n>>l>>u;
long long x;
for(i=0;i<n;++i){
f>>x;
s.push_back(make_pair(x,i));
}
sort(s.begin(),s.end());
normalizare=0;
i=0;
v[s[i++].second]=normalizare;
for(;i<n;i++) {
if(s[i-1].first!=s[i].first){
++normalizare;
v[s[i].second]=normalizare;
}
else
v[s[i].second]=normalizare;
}
g<<sub(u)-sub(l-1);
return 0;
}