Cod sursa(job #2640215)

Utilizator nicolaee2Martinescu Nicolae nicolaee2 Data 5 august 2020 17:14:38
Problema Divk Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<bits/stdc++.h>
#include<math.h>

using namespace std;

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

#define NMAX 500005

int fr[NMAX];

int main()
{
    int n,a,b,k; fin >> n>>k>>a>>b;
    vector<int> pos(n + 1, -1);

    pos[0] = 0;
    unsigned long long ps = 0;
    int sol = 0;

    for (int i = 1; i <= n; i++) {
        //cout<<i<<endl;
        int x; fin >> x;
        ps = (ps + x) % k;
        //cout<<ps<<endl;
        if (pos[ps] != -1 && (i - pos[ps] + 1 >= a && i - pos[ps] + 1 <= b)) {
            sol++;
            if(pos[0] == pos[ps]+1)
                sol++;
        }
        pos[ps] = i;
    }

    fout<<sol;



}