Cod sursa(job #37946)

Utilizator goguGogu Marian gogu Data 25 martie 2007 13:07:58
Problema Distincte Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <stdio.h>
#include <string.h>
#include <time.h>
#define MaxN 100100

int n, nr, m;
int a[MaxN];
char ok[MaxN];

int main()
{
    int i,j;
//    double timp=clock();
    freopen("distincte.in", "r", stdin);
    freopen("distincte.out", "w", stdout);
    scanf("%d %d %d", &n, &nr, &m);
    for (i=0; i<n; i++)
        scanf("%d", a+i);
    for (i=0; i<m; i++){
        int st, fn;
        scanf("%d %d", &st, &fn);
        memset(ok, 0, nr+1);
        long long sum=0;
        for (j=st-1; j<fn; j++)
            if (!ok[a[j]]) ok[a[j]]=1, sum+=a[j];
        printf("%lld\n", sum);
    }
//    printf("A durat %f secunde\n", (clock()-timp)/1000);
    return 0;
}