Cod sursa(job #2504891)

Utilizator victorv88Veltan Victor victorv88 Data 5 decembrie 2019 18:37:33
Problema Distincte Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>
using namespace std;

ifstream f("distincte.in");
ofstream g("distincte.out");

const int MOD=666013;

int n, val_max, q, st, dr, s;
int ultim[100005];
int aparitie[100005];
int a[100005];

int main()
{
    f >> n >> val_max >> q;
    for (int i=1; i<=n; ++i)
    {
        f >> a[i];
        aparitie[i]=ultim[a[i]];
        ultim[a[i]]=i;
    }
    for (int i=1; i<=q; ++i)
    {
        f >> st >> dr;
        s=0;
        for (int j=st; j<=dr; ++j)
        {
            if (aparitie[j]<st)
            {
                s+=a[j];
                s%=MOD;
            }
        }
        g << s << '\n';
    }
    return 0;
}