Cod sursa(job #2438442)
| Utilizator | Data | 12 iulie 2019 15:33:26 | |
|---|---|---|---|
| Problema | Secventa 5 | Scor | 80 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.6 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("secv5.in");
ofstream out("secv5.out");
int n,l,u;
unsigned int a[(1<<20)+1];
long long solve(unsigned int x)
{
long long ans=0,dif=0;
unordered_map<unsigned int,int> mp;
int i=1,j=1;
while(i<=n)
{
if(mp[a[i]]==0) dif++;
mp[a[i]]++;
while(dif>x)
{
mp[a[j]]--;
if(mp[a[j]]==0) dif--;
j++;
}
ans+=i-j+1;
i++;
}
return ans;
}
int main()
{
in>>n>>l>>u;
for(int i=1;i<=n;i++) in>>a[i];
out<<solve(u)-solve(l-1);
}
