Cod sursa(job #2650572)

Utilizator redstonegamer22Andrei Ion redstonegamer22 Data 19 septembrie 2020 13:28:53
Problema Divk Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

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

int sp[500005];
int f[100005];

int main()
{
    int n, k, a, b; in >> n >> k >> a >> b;

    for(int i = 1; i <= n; i++)
        in >> sp[i];

    sp[0] = 0;
    sp[1] %= k;
    for(int i = 2; i <= n; i++)
        sp[i] = (sp[i-1] + sp[i]) % k;

    /*for(int i = 0; i < n; i++)
        cout << sp[i] << " " ;
    cout << endl;*/

    long long nr_secv = 0;
    for(int i = 1; i <= n; i++)
    {
        if(i - a >= 0) f[sp[i - a]]++;
        if(i - b - 1 >= 0) f[sp[i - b - 1]]--;

        /*for(int j = 0; j < k; j++)
            cout << f[j] << " ";
        cout << endl;

        cout << sp[i] << endl;*/

        nr_secv += f[sp[i]];
    }

    out << nr_secv;
}