Cod sursa(job #2369907)

Utilizator MichaelXcXCiuciulete Mihai MichaelXcX Data 6 martie 2019 09:44:31
Problema Divk Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include    <iostream>
#include    <fstream>
#define     NMAX 500010
#define     LL long long

using namespace std;

ifstream fin("divk.in");
ofstream fout("divk.out");

LL n, k, a, b, v[NMAX], s[NMAX];

void read()
{

}

int main()
{
    read();

    fin >> n >> k >> a >> b;

    for(int i = 1; i <= n; i++)
    {
        fin >> v[i];

        v[i] = (v[i] + v[i-1]) % k;
    }

    for(int i = a; i <= b; i++)
        s[v[i]]++;

    LL cnt = 0;

    for(int i = 0; a <= n; i++)
    {
        cnt += s[v[i]];

        s[v[a]]--;

        if(b+1 <= n)
            s[v[b+1]]++;

        a++;
        b++;
    }

    fout<<cnt;

    return 0;
}