Pagini recente » Cod sursa (job #2950134) | Cod sursa (job #1882633) | Cod sursa (job #2683482) | Cod sursa (job #3131439) | Cod sursa (job #2799212)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
int n, st, dr, a[1048580];
unordered_map<int, int> M;
/// <summary>
/// 5 2 3
/// 13 13 7 9 9 13 9 13
///
/// nregale = 1
/// fr 1 2 3 4 5 6 7 8 9 10 11 12 13
/// 0 0 0 0 0 0 1 0 3 0 0 0 4
/// cnt = 2 + 3 + 3 + 5 + 6 + 7
/// </summary>
/// <returns></returns>
void Citire()
{
int i;
fin >> n >> st >> dr;
for (i = 1; i <= n; i++)
fin >> a[i];
}
void Rezolvare()
{
int i, j, nregale = 0, cnt = 0, nrdist = 0;
i = 1;
for (j = 1; j <= n; j++)
{
if (a[j] != a[j - 1]) nregale = 0;
M[a[j]]++;
if (M[a[j]] == 1) nrdist++;
while (nrdist > dr)
{
M[a[i]]--;
if (M[a[i]] == 0) nrdist--;
i++;
}
if (nrdist >= st) cnt += (j - i - nregale);
cout << cnt << " " << j << "\n";
nregale++;
}
fout << cnt << "\n";
}
int main()
{
Citire();
Rezolvare();
}