Cod sursa(job #2873236)

Utilizator sorana5Gligor Sorana sorana5 Data 18 martie 2022 22:29:43
Problema Divk Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>

using namespace std;

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

long long n, k, a, b, rez, v[500005], s[500005];

void citire()
{
    f>>n>>k>>a>>b;
    for (int i = 1; i <= n; ++i)
    {
        long long x;
        f>>x;
        s[i] = s[i-1] + x;
        s[i] %= k;
    }
}

void rezolvare()
{
    for (int i = a; i <= n; ++i)
    {
        if (i > b)
            v[s[i-b-1]]--;
        v[s[i-a]]++;
        rez += v[s[i]];
    }
}

int main()
{
    citire();
    rezolvare();
    g<<rez;

    return 0;
}