Cod sursa(job #2660004)

Utilizator nicolaee2Martinescu Nicolae nicolaee2 Data 17 octombrie 2020 23:53:25
Problema Divk Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <bits/stdc++.h>
using namespace std;

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

#define NMAX 500005

int n,k,a,b;
int x;
int sum[NMAX];
int ap[100005];



int main()
{
    fin>>n>>k>>a>>b;
    for(int i=1;i<=n;i++)
    {
        fin>>x;
        sum[i] = (sum[i-1]  + x) % k;
        //cout<<sum[i]<<" ";
    }

    long long sol = 0;
    for(int i=1;i<=n;i++)
    {
        if(i >= a)
        {
            ap[sum[i-a]]++;
        }
        if(i > b)
        {
            ap[sum[i-b-1]]--;
        }
        sol += ap[sum[i]];
    }
    fout<<sol;

    return 0;
}