Pagini recente » Cod sursa (job #925227) | Cod sursa (job #3262039) | Cod sursa (job #2460689) | Cod sursa (job #556227) | Cod sursa (job #1459695)
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#define MAXN (1 << 20) + 2
#define MOD 666013
#define list (x % MOD)
using namespace std;
struct hash_line{
unsigned int key, val;
hash_line *next;
} *G[MOD], *E[MOD];
unsigned int N, no, l, u, L[MAXN], used[MAXN];
inline unsigned int insert_val(unsigned int x){
hash_line* head = G[list];
if (!head) {
hash_line* New = new hash_line;
New->key = x, New->val = ++no, New->next = NULL;
G[list] = E[list] = New;
return no;
}
while (head){
if (head->key == x) return head->val;
head = head->next;
}
hash_line* New = new hash_line;
New->key = x, New->val = ++no, New->next = NULL;
E[list]->next = New;
E[list] = New;
return no;
}
inline long long compute(unsigned int c){
if (c < 1) return 0;
memset(used, 0, (N + 1) * sizeof(unsigned int));
long long ans = 0, j = 1;
for (unsigned int i = 1; i <= N; ++i){
if (!used[L[i]] && c) --c;
else if (used[L[i]] < j){
for (; used[L[j]] > j; ++j);
++j;
}
used[L[i]] = i;
ans += (i - j + 1);
}
return ans;
}
int main(){
freopen("secv5.in", "r", stdin);
freopen("secv5.out", "w", stdout);
scanf("%d %d %d", &N, &l, &u);
for (unsigned int i = 1, x; i <= N; ++i)
scanf("%ud", &x),
L[i] = insert_val(x);
printf("%lld", compute(u) - compute(l - 1));
return 0;
}