Pagini recente » Borderou de evaluare (job #65549) | Borderou de evaluare (job #72763) | Rezultatele filtrării | Cod sursa (job #1642463) | Cod sursa (job #3354354)
#include <iostream>
#include <fstream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define all(x) x.begin(), x.end()
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
const int nmax = (1 << 20);
int n, l, r;
int fr1[nmax + 5];
int fr2[nmax + 5];
int v[nmax + 5];
int secvente(int l, int r) {
int secv = 0;
int d1 = 0;
int d2 = 0;
/// dr1 -> cea mai mica pozitie unde int[st, dr1] contine exact l elem dist
/// dr2 -> cea mai mica pozitie unde int[st, dr2] contine exact r elem dist
for (int st = 1, dr1 = 0, dr2 = 0; st <= n; ++st) {
while (dr1 < n and d1 < l) {
fr1[v[++dr1]]++;
d1 += (fr1[v[dr1]] == 1);
}
while (dr2 < n and d2 <= r) {
fr2[v[++dr2]]++;
d2 += (fr2[v[dr2]] == 1);
}
if (d2 > r) {
d2 -= (fr2[v[d2]] == 1);
fr2[v[dr2]]--;
dr2--;
}
if (d1 == l and d2 <= r) {
secv += dr2 - dr1 + 1;
}
fr1[v[st]]--;
fr2[v[st]]--;
d1 -= (fr1[v[st]] == 0); d2 -= (fr2[v[st]] == 0);
/*
fout << st << " " << dr1 << " " << dr2 << '\n';
fout << "de la " << st << " la " << dr1 << " sunt " << d1 << " elem dist\n";
fout << "de la " << st << " la " << dr2 << " sunt " << d2 << " elem dist\n";
*/
}
return secv;
}
int main() {
fin >> n >> l >> r;
for (int i = 1; i <= n; ++i) {
fin >> v[i];
}
fout << secvente(l, r);
}