Cod sursa(job #2438441)
| Utilizator | Data | 12 iulie 2019 15:31:02 | |
|---|---|---|---|
| Problema | Secventa 5 | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("secv5.in");
ofstream out("secv5.out");
int n,l,u,a[(1<<20)+1];
long long solve(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()
{
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
in>>n>>l>>u;
for(int i=1;i<=n;i++) in>>a[i];
out<<solve(u)-solve(l-1);
}
