Pagini recente » Cod sursa (job #1190843) | Cod sursa (job #1587566) | Cod sursa (job #1610751) | Cod sursa (job #429944) | Cod sursa (job #858751)
Cod sursa(job #858751)
#include <fstream>
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
#define MAXN 1 << 21
#define MOD 666013
#define int unsigned int
int N, L, U;
vector<int> sir(MAXN);
vector< pair<int, int> > hash[MOD];
void insert_hash(int val, int indic) {
hash[val % MOD].push_back(make_pair(val, indic));
}
int get_indic(int val) {
int poz = val % MOD;
for (int i = 0; i < hash[poz].size(); ++i)
if (hash[poz][i].first == val)
return hash[poz][i].second;
return 0;
}
void read() {
fin >> N >> L >> U;
for (int i = 1; i <= N; ++i)
fin >> sir[i];
}
void normalize() {
int on = 0;
for (int i = 1; i <= N; ++i) {
int rez = get_indic(sir[i]);
if (rez == 0) {
insert_hash(sir[i], ++on);
sir[i] = on;
}
else sir[i] = rez;
}
}
int how_much[MAXN];
int solve(int limit) {
int nr = 0, st = 1, rez = 0;
memset(how_much, 0, sizeof(how_much));
for (int i = 1; i <= N; ++i) {
if (how_much[sir[i]] == 0)
++nr;
++how_much[sir[i]];
if (nr > limit) {
while (1){
--how_much[sir[st]];
++st;
if (how_much[sir[st - 1]] == 0)
break;
}
--nr;
}
rez += i - st + 1;
}
return rez;
}
void print() {
fout << solve(U) - solve(L - 1);
}
#define int int
int main() {
read();
normalize();
print();
return 0;
}