Cod sursa(job #2039440)
| Utilizator | Data | 14 octombrie 2017 16:02:41 | |
|---|---|---|---|
| Problema | Secventa 5 | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
unsigned n,u,l,a[2000000];
long long Rezolvare(int k)
{unsigned i,j,x;
long long cnt=0;
i=1;
unordered_map<unsigned,int>M;
for(j=1;j<=n;j++)
{M[a[j]]++;
while(M.size()>k)
{x=a[i];
M[x]--;
i++;
if(M[x]==0)M.erase(x);
}
cnt+=1LL*j-1LL*i+1LL;
}
return cnt;
}
int main()
{int i;
fin>>n>>l>>u;
for(i=1;i<=n;i++)
fin>>a[i];
fout<<Rezolvare(u)-Rezolvare(l-1);
}
